Graphic Expert Advisor: AutoGraf

Сергей Ковалев | 9 January, 2007

 

Who of traders did not dream of the possibility just to drag the order with a mouse and place it on another level or to do the same with its StopLoss and TakeProfit? A convenient interface is very important for a trader, if he or she trades daily.

MetaQuotes Language 4 (MQL4) favorably compares to its ancestor, MQL 2, through it allows the programmer to process coordinates of shape objects. The importance of this fact cannot be overestimated.

A graphic Expert Advisor, AutoGraf, is graphic in the sense that shape objects are used in it in order to create a convenient interface. We will call AutoGraf a software complex or an application as it contains both an Expert Advisor, a script and an indicator.

The application is rather large (87 files, over 10 000 lines). Thus, it is not practical to consider all technical solutions thereof in only one exploratory article. Therefore, other materials that can be of interest for programmers will be published in other articles  where we will discuss single code fragments and their specifics in more details.

Let us consider the structure of the application and its feautures important to users.

 

1. Basic Properties and Features of the Application

The application has the following basic functions:

1. Open orders of all types without using the MT 4 "New Order" toolbar.

2. Close one or several orders of all types using the Delete button.

3. Modify orders of all types using the mouse to move horizontal lines that are placed according to the order characteristics.

4. Modify orders automatically using the algorithm predefined in tools.

 

2. General View of the Application

To know the worth of graphical tools, it would be the best way to install the application on the PC and get practical experience with it. For this, it is necessary to move all files from the archive to the directories of the same names in the MetaTrader4 Client Terminal directory. Close the МТ4 Client Terminal, copy files and restart the terminal. Then it is necessary to compile 3 files. To do so, open MetaEditor.exe (in the МТ4 root directory) and compile the following files one by one: AutoGraf_expert.mq4, AutoGraf_script.mq4, and AutoGraf_indic.mq4. Now the files should be attached to the window and start working.

Let us study the basic components of the application.

 

Indicator window is located in the bottom of the screen. It is used for messages generated by the application during the work. In the right corner of the indicator window, there is an icon that shows the control panel.

In the right part of the terminal window, the opened control panel with tools located on it is shown. The control panel can be shown or hidden using the icon. It is sufficient to select it with the mouse, move aside and drop. As a result, the control panel will appear or disappear in the main window of the terminal.

 

3. Order Lines

Lines of open and pending orders are shown in the main window. Let us study working with orders in more details.

Order lines (OpenPrice, StopLoss and TakeProfit) of any order type is shown in the window in the color defined in the expert settings. Trader can change the line color. But the line type is strictly predefined in the application and cannot be changed by trader:

- solid line - for open orders;
- dashed line - for pending orders;
- dash-and-dot line  - for StopLoss of any orders;
- dotted line - for TakeProfit of any orders.

Trader can move any order lines except for the OpenPrice line of an open order, this means it is possible to change order parameters, delete the order or zeroize one of its parameters. For this, it is necessary to select the "Horizontal Line" object that covers the order and move it using the mouse to the desired level or delete it using the corresponding key. As soon as trader drops the line in the desired location (or deletes it), the following events will take place:

1. The "Horizontal Line" object will return to the current level of the order line confirming its current location.

2. The application will command the server to modify or delete orders or their parameters according to the trader's control.

3. If the trader performs control, which is inconsistent with reason or beyond the scope of the accepted tolerable limits, the application can deny sending the command to the server or it can change the modification parameters set by the trader and inform the trader about it in the indicator window.

4. As soon as the command is executed on the server, the order line will move to the new location and "Horizontal Line" will move, as well, covering the order line.

5. If the server denies execution of the command, the application will describe the reason for rejection and the trader's control will be canceled. Re-requesting of the trader's control execution will not be made automatically. The trader can repeat his or her control by repeating the movement or deletion of the "Horizontal Line" object.

Any combinations of order lines, including open and pending orders, can be deleted simultaneously. In this case, the application will send commands to the server to close or modify orders according to the following priorities:

1.  Closing Orders.
    1.1. Closing of open orders.
    1.2. If 2 counter-orders should be closed (including those to be closed automatically), the counter-closing will take place, either partial or full.
    1.3. Closing of the heaviest order of those to be closed manually.
    1.4. Deletion of pending orders.
2.  Modifying Orders.
    2.1. Modification of open orders.
    2.2. Modification of pending orders.
    2.3. Modification of the order most distant from the "goal course".
    2.4. Modification of the heaviest of those (manually at the same time) to be modified.
3. The latest order has the highest priority.

The following can be done for better understanding how multiple orders are closed in practice. Open a couple of orders of different types, for example, Buy with 1.5 lots, Sell for 1 lot, BuyLimit and SellLimit of different volumes. Then place disorderly StopLosses and TakeProfits for those orders. Now select order lines of Buy, Sell and BuyLimit, as well as TakeProfit of the SellLimit using your mouse and press Delete. All selected orders and their parameters will be closed or deleted. Now you can view in the corresponding *.log file what and in what sequence has been executed by the program.

 

4. Control Panel

The program allows trading using custom graphical tools, which include graphical tools place on the Control Panel.
 

The Control Panel includes the following elements:

1. The Control Panel itself. It is a light brown rectangle. This object can be selected, resized or moved using the mouse. The Control Panel cannot be deleted by pressing Delete - if you try to do it, the program will return the corresponding warning. If you want to hide the Control Panel, use the control icon.

If the amount of bars visible in the chart is changed (in case of zooming), the Control Panel retains its size and location set by the user. The operability of all tools in the Control Panel is supported irrespective of whether it is relocated or hidden.

2. Control lines.

3. Box lines and scale of order parameters.

4. Lots icon and lots scale.

5. Function icon and functions scale.

 

4.1. Control Lines

These are 18 lines of different colors that determine the corresponding parameters of orders of different types. Lines of the same color determine parameters of one order.
 


The upper row of lines of one color determine orders placed above the exchange rate, the lower row does those placed below the rate. In the upper row, order lines of BuyStop, Buy and SellLimit are shown, respectively from left to right. In the lower row, BuyLimit, Sell and SellStop.

Solid lines mark opening of evident orders, dashed lines - opening rate of pending orders, dash-and-dot lines - StopLoss, dotted lines - TakeProfit.

Control lines are used to place orders and set their parameters. One control line is used for one order or for one its parameters.

Opening Orders

To open an order, it is necessary to select the solid line and drag it with the mouse to any location in the main window. This control will result in opening an order at the current rate.

Placing Pending Orders

To place a pending order, it is necessary to select the dashed line and drag it to the window. This control will result in opening a pending order at the rate defined by the trader, i.e., in the location where the trader locates the control line.

Defining Parameters of Open and Pending Orders

To define levels of StopLoss and TakeProfit for existing orders with pre-defined zero values of StopLoss and TakeProfit the dash-and-dot and dotted lines of the corresponding color should be used. The defining order is the same: drag the line to the desired rate in the window.

Provided there are two or more orders of the same names with zero values of StopLoss or TakeProfit in the window, the control line will define the corresponding stop level for the last placed order. The next control line will do for the last but one order, etc.

Control line may not apply to any levels of stop orders other than zero. For example, if the trader has drawn the order StopLoss line that has already had a value other than zero, this will not have any effect on the order. The trader will be informed about it with a special warning.

The Control Lines may not be deleted.

 

4.2. Box Lines

These are three lines of the same color that determine the corresponding characteristics of orders of different types. Lines of the same color define characteristics of the same order.


 

Box content. To set up the order to be opened, it is necessary to select and move any of the Control Lines. This will result in that three lines of one color that unambigously define the characteristics of the order to be opened will appear in the Box.

Deletion of any Box Lines will empty the Box, but it won't have any effect on trading.

The Box order will be set up by selecting the corresponding values in the order settings.

To view the settings scale, it is necessary to select and move SL, TP or the right-hand figure. The preset value for StopLoss and TakeProfit is Dist set on the Expert settings panel.

To choose a StopLoss/TakeProfit value from those given in the scale, it is necessary to select and move the chosen value. The trader's choice will be shown near the corresponding setting. Zero values  are allowed.

The order is opened and placed by dragging the OpenPrice middle line to the main window. Lines of StopLoss/TakeProfit may not be dragged. The order is opened according to the settings shown in the Box.

To open an order, it is necessary to select the middle line and drag it with the mouse to any location in the main window. This will result in opening an order at the current rate.

To place pending orders, it is necessary to select and drag the dashed line to the main window. This will result in placing a pending order at the rate defined by the trader, i.e., in the location where the trader drops the Control Line.  

 

4.3. Determining of Lots Amount

To determine the order volume, it is necessary to select one of the values shown in the scale.

Amount of lots directly influences the orders to be opened whatever type they are, but it does not have any effect on the amount of lots in the orders to be modified of whatever modifying initialization source.

To show the lots scale, it is necessary to select and move the number of green color. This will result in showing a part of the lots scale with values around the number shown in green.

Moving down the lots number sign will result in showing the left part of the scale, moving it up - in showing the right part of the scale.

Volumes for orders to be opened are selected by moving any value in the visible part of the scale in any direction. The selected value will be shown as a number sign, the scale will disappear.

The scale values and the number sign may not be deleted.

 

4.4. Choosing a Function

To choose a control function, it is necessary to select one of values in the scale.


 

To show the functions scale, it is necessary to select and move the symbol of the current function (it is Fn in our example above). This will result in showing of the functions scale.

Trader can select a function by moving any of the values shown in the scale in any direction. The selected value will be shown as a symbol, the scale will disappear.

The scale values and function symbol may not be deleted.

Any selected function will stop the previously operating function, all preceding settings will be canceled. If the Fn value has been selected, all functions will be stopped.

 

5. Control Tools

The program allows trading with Control Tools of the AG function.

 


 

The following Control tools are supported: Drag Up, Drag Down, Along the Trend, Stop-0 for Buy, Stop-0 for Sell, Drag but not above, Drag but not below, Close by Touch.

Controls of the server are working according to the following priorities:


1. Closing orders.
    1.1. Closing of open orders.
    1.2. Pending orders may not be deleted automatically.
    1.3. Closing of the heaviest order of those to be closed.
2. Modifications of orders.
    2.1. Modify order that is the most remote from the "goal course".
    2.2. Modification of open orders.
    2.3. Modification of pending orders.
    2.4. Modification of the heaviest order of those to be modified.
    2.5. Modification of the order that has been created later.
3.  No automated opening.
 

5.1. Drag Up  

The control setting named Drag Up of the AG function is intended for modifying of open and pending orders - dragging the corresponding characteristics of the order in the upper direction (not to be confused with standard setting of МТ4 named TralingStop that drags only StopLoss of the order, only in the trend direction and only in the positive area). The order line will be dragged on the distance predefined by the user from or to the trend depending on the order type. The setting can be set for the following order lines:

StopLoss of an open order of any type.

TakeProfit of an open order of any type.

OpenPrice of a pending order of any type.

The control setting Drag Up may not be set on other order lines.

The setting is mutually exclusive towards settings  named Drag Down and Along the Trend.

To set it for the selected order line, it is necessary to select and drag with the mouse the setting symbol to the line. If the line selected by the trader corresponds with the setting, its symbol will "stick" to the line and follow the order until it is closed or the setting symbol is deleted.

Deletion of the setting symbol will result in canceling the order line setting Drag Up.

The number shown near the setting symbol means the distance, at which the order line follows the trend (or runs from it).

If the order line has changed its location towards the rate not as a result of dragging, but as a result of another control by the trader, the number that shows the distance of the dragging can change according to that set by the trader.

(For example, when placing the setting for the StopLoss of a Buy order:

- if the order line has been moved down by the trader, the distance will be extended;

- if the order line has been moved up by the trader, the distance will remain the same.)

Vertical moving of the control symbol is directly related to changes in the order line following distance.

Horizontal moving of the control symbol has no relation to the control setting. This is an allowed operation and lets the trader to place the symbol where it is convenient (for instance, clear of the trendline).

The number that shows the distance may not be moved or influenced in any other way.

If the order line to be modified touches the rate preset by the setting Drag but not above, both Drag Up and Drag but not above will be canceled automatically.

 

5.2. Drag Down

The control setting named Drag Down of the AG function is intended for modifying of open and pending orders - dragging the corresponding characteristics of the order in the lower direction (not to be confused with standard setting of МТ4 named TralingStop that drags only StopLoss of the order, only in the trend direction and only in the positive area). The order line will be dragged on the distance predefined by the user from or to the trend depending on the order type. The setting can be set for the following order lines:

StopLoss of an open order of any type.

TakeProfit of an open order of any type.

OpenPrice of a pending order of any type.

The control setting Drag Up may not be set on other order lines.

The setting is mutually exclusive towards settings  named Drag Up and Along the Trend.

To set it for the selected order line, it is necessary to select and drag with the mouse the setting symbol to the line. If the line selected by the trader corresponds with the seting, its symbol will "stick" to the line and follow the order until it is closed or the setting symbol is deleted.

Deletion of the setting symbol will result in canceling the order line setting Drag Down.

The number shown near the setting symbol means the distance, at which the order line follows the trend (or runs from it).

If the order line has changed its location towards the rate not as a result of dragging, but as a result of another control by the trader, the number that shows the distance of the dragging can change according to that set by the trader.

(For example, when placing the setting for the StopLoss of a Sell order:

- if the order line has been moved down by the trader, the distance will remain the same;

- if the order line has been moved up by the trader, the distance will be extended.)

Vertical moving of the control symbol is directly related to changes in the order line following distance.

Horizontal moving of the control symbol has no relation to the control setting. This is an allowed operation and lets the trader to place the symbol where it is convenient (for instance, clear of the trendline).

The number that shows the distance may not be moved or influenced in any other way.

If the order line to be modified touches the rate preset by the setting Drag but not below, both Drag Down and Drag but not below will be canceled automatically.

 

5.3. Along the Trend

The control setting Along the Trend of the AG function is intended for modifying open and pending orders - holding the corresponding characteristic of the order in the location "along the trend". The order line is held at the distance from the current rate preset by the user. The order line is modified if its distance from the current rate has changed by a value exceeding the Luft value preset by the trader in the Expert Advisor's settings. Along the Trend can be set for the following order lines:

StopLoss of an open order of any type.

TakeProfit of an open order of any type.

OpenPrice of a pending order of any type.

The control setting Drag Up may not be set on other order lines.

The setting is mutually exclusive towards settings named Drag Up and Drag Down.

To set it for the selected order line, it is necessary to select and drag with the mouse the setting symbol to the line. If the line selected by the trader corresponds with the seting, its symbol will "stick" to the line and follow the order until it is closed or the setting symbol is deleted.

Deletion of the setting symbol will result in canceling the order line setting  Along the Trend.

The number shown near the setting symbol means the distance, at which the order line follows the trend.

If the order line has changed its location towards the rate not as a result of dragging, but as a result of another control by the trader, the number that shows the distance of the dragging will not change. In this case, the program executing the setting will give a command to the server to modify the order line according to the distance preset by the trader.

Vertical moving of the control symbol is directly related to changes in the order line following distance.

Horizontal moving of the control symbol has no relation to the control setting. This is an allowed operation and lets the trader to place the symbol where it is convenient (for instance, clear of the trendline).

The number that shows the distance may not be moved or influenced in any other way.

 

54. Stop-0 for Buy 

The control setting Stop-0 for Buy of the AG function is intended for modifying StopLoss of a Buy order.  The control setting Stop-0 for Buy may not be placed on other order lines.

The order line will be modified if the rate is equal to or above the value set by the Stop-0 for Buy. The StopLoss order line of the Buy order will be placed at the open price of the order automatically.

The control setting Stop-0 for Buy does not have any mutually exclusive settings.

To place the setting of the selected order line, it is necessary to select and drag the setting icon with the mouse to the order line. If the line selected by the trader corresponds with the setting, the setting icon will be placed above the order line at the preset distance according to the Tjaga value in the Expert Advisor's settings, and it will follow the order until either it is closed or the setting is deleted, or the modification is made according to the setting.

The StopLoss modification for a Buy order according to the setting Stop-0 for Buy will result in cancelling the setting and deletion of the setting icon.

The deletion of the setting icon will result in cancelling the setting Stop-0 for Buy.

The number shown near the setting icon means the amount of points above the order Open price and cannot be less than the limiting distance established by the dealing center.

Vertical moving of the control symbol is directly related to changes in the setting execution distance.

Horizontal moving of the control symbol has no relation to the control setting. This is an allowed operation and lets the trader to place the symbol where it is convenient (for instance, clear of the trendline).

The number that shows the distance may not be moved or influenced in any other way.

The Stop-0 for Buy can be used simultaneously with the setting Drag Up. The Stop-0 for Buy will be cancelled after execution while the Drag Up setting will remain.

It is not recommended to use the setting Stop-0 for Buy together with the setting Along the Trend. Where these settings are used together, the Stop-0 for Buy setting will be cancelled at execution and the setting Along the Trend will return the Buy order StopLoss back to the distance that follows Along the Trend.

 

5.5. Stop-0 for Sell 

The control setting Stop-0 for Sell of the AG function is intended for modifying StopLoss of a Sell order.  The control setting Stop-0 for Sell may not be placed on other order lines.

The order line will be modified if the rate is equal to or above the value set by the Stop-0 for Sell. The StopLoss order line of the Sell order will be placed at the open price of the order automatically.

The control setting Stop-0 for Sell does not have any mutually exclusive settings.


To place the setting of the selected order line, it is necessary to select and drag the setting icon with the mouse to the order line. If the line selected by the trader corresponds with the setting, the setting icon will be placed below the order line at the preset distance according to the Tjaga value in the Expert Advisor's settings, and it will follow the order until either it is closed or the setting is deleted, or the modification is made according to the setting.

The StopLoss modification for a Sell order according to the setting Stop-0 for Sell will result in cancelling the setting and deletion of the setting icon.


The deletion of the setting icon will result in cancelling the setting Stop-0 for Sell.

The number shown near the setting icon means the amount of points below the order Open price and cannot be less than the limiting distance established by the dealing center.

Vertical moving of the control symbol is directly related to changes in the setting execution distance.

Horizontal moving of the control symbol has no relation to the control setting. This is an allowed operation and lets the trader to place the symbol where it is convenient (for instance, clear of the trendline).

The number that shows the distance may not be moved or influenced in any other way.

The Stop-0 for Sell can be used simultaneously with the setting Drag Down. The Stop-0 for Sell will be cancelled after execution while the Drag Down setting will remain.

It is not recommended to use the setting Stop-0 for Sell together with the setting Along the Trend. Where these settings are used together, the Stop-0 for Sell setting will be cancelled at execution and the setting Along the Trend will return the Sell order StopLoss back to the distance that follows Along the Trend.

5.6. Drag but not above

The control setting Drag but not above of the AG function is intended for limitations in modification of the order line when using settings of Drag Up or Along the Trend.

The setting can be placed only provided the Drag Up or the Along the Trend settings are placed on the following order lines:

StopLoss of an open order of any type.

TakeProfit of an open order of any type.

OpenPrice of a pending order of any type.

The control setting Drag but not above may not be set on other order lines.

The control setting Drag but not above does not modify orders.

To place the setting of the selected order line, it is necessary to select and drag the setting icon with the mouse to the order line. If the line selected by the trader corresponds with the setting, the setting icon will be placed below the order line at the preset distance according to the Tjaga value in the Expert Advisor's settings, and it will follow the order until either it is closed or the setting Drag but not above (or Drag Up, or Along the Trend) is deleted, or the modification is made according to the setting.

When being placed, the Drag but not above setting icon will change its color for the color of the order line, on which the setting is placed.

Modification of the order according to the setting Drag but not above the level, which is equal to or above the rate of the setting Drag but not above, will result in cancelling the setting Drag but not above, the accompanying setting Drag Up, as well as in deletion of icons of these settings.

Modification of the order according to the setting Along the Trend to the level, which is equal to or above the rate of the setting Drag but not above, will result in disabling execution of the order modification according to the setting Along the Trend, but it does not result in cancelling the setting Drag but not above, the accompanying setting Along the Trend, or deletion icons thereof.

Deletion of the icon will result in cancelling the setting Drag but not above.

The number shown near the setting symbol means the amount of points above the current rate of the order line, is restricted by the value of 1 pt and is not related to the limiting distance established by the dealing center.

Vertical moving of the control symbol is directly related to changes in the setting execution distance.

Horizontal moving of the control symbol has no relation to the control setting. This is an allowed operation and lets the trader to place the symbol where it is convenient (for instance, clear of the trendline).

The number that shows the distance may not be moved or influenced in any other way.

 

5.7. Drag but not below

The control setting Drag but not below of the AG function is intended for limitations in modification of the order line when using settings of Drag Down or Along the Trend.

The setting can be placed only provided the Drag Down or the Along the Trend settings are placed on the following order lines:

StopLoss of an open order of any type.

TakeProfit of an open order of any type.

OpenPrice of a pending order of any type.

The control setting Drag but not below may not be set on other order lines.

The control setting Drag but not below does not modify orders.

To place the setting of the selected order line, it is necessary to select and drag the setting icon with the mouse to the order line. If the line selected by the trader corresponds with the setting, the setting icon will be placed below the order line at the preset distance according to the Tjaga value in the Expert Advisor's settings, and it will follow the order until either it is closed or the setting Drag but not below (or Drag Down, or Along the Trend) is deleted, or the modification is made according to the setting.


When being placed, the Drag but not below setting icon will change its color for the color of the order line, on which the setting is placed.

Modification of the order according to the setting Drag but not below the level, which is equal to or below the rate of the setting Drag but not below, will result in cancelling the setting Drag but not below, the accompanying setting Drag Down, as well as in deletion of icons of these settings.

Modification of the order according to the setting Along the Trend to the level, which is equal to or below the rate of the setting Drag but not below, will result in disabling execution of the order modification according to the setting Along the Trend, but it does not result in cancelling the setting Drag but not below, the accompanying setting Along the Trend, or deletion icons thereof.

Deletion of the icon will result in cancelling the setting Drag but not below.

The number shown near the setting symbol means the amount of points below the current rate of the order line, is restricted by the value of 1 pt and is not related to the limiting distance established by the dealing center.

Vertical moving of the control symbol is directly related to changes in the setting execution distance.

Horizontal moving of the control symbol has no relation to the control setting. This is an allowed operation and lets the trader to place the symbol where it is convenient (for instance, clear of the trendline).

The number that shows the distance may not be moved or influenced in any other way.

5.8. Close by Touch  

The control setting Close by Touch of the AG function is intended for closing orders of Buy and Sell types. The setting can be placed only on the OpenPrice order line of Buy/Sell orders. The setting may not be placed on any other order lines.

The order will be closed if the currency rate is equal to or above (for Sell orders - below) the level set by the Close by Touch. 

The setting Close by touch does not have any mutually exclusive settings.

To place the setting, it is necessary to select and drag the setting icon with the mouse to the OpenPrice line of the order. If the line selected by the trader corresponds with the setting, the setting icon will be placed above (for Sell orders - below) the order line at the preset distance according to the Tjaga value in the Expert Advisor's settings, and it will follow the order until either it is closed or the setting is deleted.

When being placed, the Drag but not below setting icon will change its color for the color of the order line, on which the setting is placed.

Execution of the setting Close by Touch will result in cancelling the setting and deletion of the setting icon.

Deletion of the icon will result in cancelling the setting Close by Touch.

The number shown near the setting symbol means the amount of points above the open price of the order line, is restricted by the minimal value of 1 pt and is not related to the limiting distance established by the dealing center.

Vertical moving of the control symbol is directly related to changes in the setting execution distance.

Horizontal moving of the control symbol has no relation to the control setting. This is an allowed operation and lets the trader to place the symbol where it is convenient (for instance, clear of the trendline).

The number that shows the distance may not be moved or influenced in any other way.

 

6. Application Specifics

Be careful and attentive when using selection of graphical objects. Due to the application specifics, symbols of some control settings are shown near to horizontal lines of orders. When treated inattentively, graphical objects can be selected that were not planned for this by the trader. The consequent changes in objects' locations (or deletion thereof) can cause generation of unplanned controls.

If you face difficulties selecting objects, you can use the list of objects available in the main window (press F3).

It is recommended to use the accompanying sounds. At the initial stage, one can suppose the use of sounds is needless. However, it will be much more convenient for you to get information about your trading using the sounds.

 

7. How to Use

The given application version is distributed as a freeware and without any limitations.

You will find attached the application source code, instructions and some wave files that I suppose to be useful.

The extended version of the application is under development now. Information about this new version is available at the author's website at:  http://AutoGraf.dp.ua/ .

SK. Dnipropetrovsk. 2006.