It's hard to eliminate errors when writing considerably complicated programs. MetaEditor offers you the built-in debugger to help you solve this problem. The debugging of applications consists in the possibility of the step-by-step program execution, calculating local variables, setting at breakpoints in a preset location.
Further the debugging process is described in details:
Before you start the program debugging, it's necessary to check its parameters in the "Debugging" tab of the MetaEditor options window. In this window you can specify a symbol and a chart period, in which the debugging of applications will be performed. Such a chart will be temporarily created each time when debugging is started, and it will be deleted after the debugging completion.
A breakpoint is a command that triggers when the program execution is passed to an indicated line and stops the program in this location. Breakpoints allow analyzing the program behavior in a selected location: viewing values of variables, stack of functions. After that the debugging process can be continued or completed.
Before you start debugging, place such breakpoints in necessary code positions. To do this, click twice by the left mouse-button on the gray field near the left border of the code line. You can also place the mouse cursor in the necessary line and execute the " Toggle Breakpoint" command of the "Debug" menu or in the "Standard" toolbar, or you can press the "F9" key. Breakpoints are disabled the same way.
To start the debugging process, it's necessary to open a program file, selecting it in the "Navigator" window. After that execute the " Start Debugging" command in the "Debug" menu or in the "Standard" toolbar, or press the "F5" key. After that the program to debug will be attached to a special chart in the trading terminal. As soon as the program execution reaches the line with the first breakpoint, it will be stopped. The point where the execution is stopped will be changed into . Besides, the "Debugging" tab will appear in the "Toolbox" window. In its left part the stack of function call will be shown.
In the process of debugging you can watch values of different expressions (variables) obtained at this program execution stage. For these purposes the right part of the "Debug" tab in the "Toolbox" window is used. An expression can be added in the following ways:
In the expressions watching window, you can conduct simple mathematical calculations (addition, subtraction, multiplication and division), as well as view values in certain array points. For example, you can indicate a record like A, where A is the name of an array, 3 and 4 are positions in its dimensions. When adding objects to observed expressions, the list of its members can be shown by adding a point at their end or pressing "Ctrl+Space":
The left part of the "Debug" tab in the "Toolbox" window allows viewing stacks. Here the following components are shown:
When the debugging process is started, only the address of a called function, at which a breakpoint has triggered, is shown in this window.
For executing the above commands, the debugging process must be stopped. This is done automatically when program execution reaches a breakpoint. Also debugging can be suspended manually by pressing " Break Debugging" in the "Debug" menu or in the "Standard" toolbar, or by pressing the "Break" key.
The breaking of the program debugging process is done automatically, when it reaches a line with a breakpoint. However, the debugging process can be managed manually:
MetaTrader 5 — a complex trading platform for providing brokerage services on the retail Forex market.
Copyright 2000-2015, MetaQuotes Software Corp.