Wednesday, February 4, 2009

Programming in MQL II. How do you find an error 2

Programming in MQL II. How do you find an error, continue

In the last issue of the journal (ForexMagazine April 2004, ? 14), we examined one of the easiest but at the same time, and one of the most useful way to debug programs - instruction language MQL II print (). In order not to overburden material, nothing was mentioned about Analogs command printf (), which is also output information about the program. Function print () prints in a special window of MetaTrader Journal referred to it as a parameter string. Teams alert () and comment () can be used, as well as print () with the only difference being that they are in another display of lines: comment () prints the information in the upper left corner of the window to the schedule (Figure 1 arrow 1) and alert () displays information in a separate dialog box pops (Figure 1 arrow 2).



Parameters for all three functions can be any type of data allowed syntax of the language MQL II. All variables passed as parameters to these functions, a type were not correctly converted into a string. Let's look at examples of various options.












Instruction Alert ( "first parameter =" +100 + "second parameter =" + 200), displays the following dialog box:
In order to show only the date or time of use TimeToStrEx

UP to this point dealt with the debugging, as such, but anyone who in the design experts to try to find the error above proposed methods, probably faced with some inconvenience - on screen or in a journal written in an enormous amount of information, which later is not very convenient to operate. Especially for debugging Experts MQL II developers added the ability SetDebugMode (). Its purpose - to indicate whether MetaTrader'u output debugging information in the Journal window, or redirect it in a separate file. Also, this feature can be used to control over what information will be displayed during debugging. As parameters it takes three values: MODE_FILE, MODE_VALUES, MODE_DETAILS.

Parameter MODE_FILE - makes MetaTrader output debugging information in a separate file, which after the completion of the expert will be located in the subdirectory "logs" to the directory where the installed MetaTrader. If the expert is named "test" is attached to the time schedule EURUSD, the file will be named "testEURUSD60.log". Details on the formation of the file name can be found from the site MetaQuates Software (http://www.metaquotes.ru/advisors/mql.htm see description of SetDebugMode).

Parameter MODE_VALUES - makes MetaTrader output values of all variables in the expert institutions.

Parameter MODE_ DETAILS - makes MetaTrader display additional information on the work of an expert: the duration, the number of instructions, etc.

In addition, the parameters of the function SetDebugMode () can be arbitrarily combined, piling them to one another. For example, you can call this function so SetDebugMode (MODE_FILE + MODE_VALUES) and both wish to be simultaneously taken into account - the values of all variables in the expert institutions will be saved in a special file.

In order to undo the previous function call SetDebugMode () should cause it to zero as a parameter.

Finally I would like to draw your attention to another very moschnuyu opportunity debugging experts. It stands apart from the above methods, as is not in any program "stunt." So what I am talking about - this visualization of transactions carried out by your expert. Just at the time of testing, an expert in Strategy Tester'e specify that you want to see the operations carried out by an expert. To do this, check on "Arrows on the chart" as the arrow shown in Figure 5:
Fig.5

Before you in the process of testing right on schedule, on which you put the expert, will show the symbols of opening and closing of lots, checking that you'll be able to form a preliminary view on the fidelity of the algorithm is an expert! This possibility greatly saves time, because it enables them to visually identify gross errors without waiting for the end of testing expert.

Now you have everything you need to debug applications. Find errors in the programs - a very broad topic, so to speak - is a whole art. There is a legend that one day the problem of debugging programs faced the engineers of one of the research laboratories. They have long fought over a bad program, and eventually found that the crash was caused by short circuit in the electrical circuits of the computer. Little zhuchek, zapolzshy in the computer violated his work, and just was not brought to mind Our experience engineers. The English word "bug" (bug) has called the process of finding problems in the program. Since then, debugging programs and search for errors is called "debug". We are confident that each of you with the advent of programming experience accumulated their own methods of extraction of "bugs" in the code. The aim of this same material was available to introduce you to the language MQL II methods of finding errors.



Alexander Ivanov
to Forex Magazine

No comments: