Creating EAs and Indicators with the MQL Wizard

0

Having an in-depth knowledge of the programming languages such as Lua or MQL is no longer a prerequisite for being able to create forex trading robots. Prior to this time, a lack of programming skills created a huge obstacle to the ability of traders to implement their own trading strategies. However, all this has now changed with the emergence of a powerful feature of the new MT4 Build 600 platform’s MQL Wizard. This has put the power of MQL programming in the hands of even newbie traders, who previously had to worry about giving out their secrets to strangers with the ever-present fear of the source code hitting the black market, or had to put up with programmers not properly implementing their strategies. Novice traders no longer need to worry about the lack of programming experience, because with the new Wizard, a trader can generate his or her own Expert Advisor code! This program actually takes the work off the trader and does all the dirty work by itself.

A successful Expert Advisor will consist of three modules that operate independently:

  1. Signals
  2. Money management
  3. Trailing stop

Due to the fact that the modules can be implemented in various ways, several possible combinations of Expert Advisors can be generated. Thus, it is possible to construct an Expert Advisor to one’s own taste and liking. All that needs to be done is to highlight the desired parameters and choose the components that are deemed necessary, and the MQL5 Wizard will take up the job from there. For the first time, the act of creating forex trading robots has been rendered so quick and simple. Indeed with just four clicks, a trader can have his or her own Expert Advisor up and ready to be put to use in the forex market.
But before we go on to describe how to create indicators and expert advisors using the MQL Wizard, let us describe this Wizard a little so traders get to know a little about this great tool.

 

The MQL Wizard

 

The MQL Wizard is a new feature of MetaEditor that helps to produce software based on the MQL4/MQL5 programming languages such as indicators and expert advisors. With the MQL Wizard, a trader can develop indicators and Expert Advisors without having any programming skills. All that the trader needs to do is to select trading signals for an Expert Advisor, and set the money management and trailing stop algorithms. The MQL Wizard then takes up the task from there and generates the Expert Advisor code automatically based on the selected parameters.

In addition, the MQL Wizard also allows the trader to create MQL programs templates, so that the work of programmers in creating future software can be made a lot simpler. In MQL a template is defined as a file that is designed for writing of source code for MQL software.

After a template has been created, it can be automatically placed in the appropriate directory, depending on the selected type of MQL4/MQL5 program. In a previous article in which we described the changes made to the MT4 in its Build 600 version, we clearly stated that indicators are now placed in a different directory and expert advisors placed in a different directory. This is what the MQL Wizard does with a created template: sorts it out according to software type and then lodges it in the appropriate directory.

The MQL Wizard can be opened from the MT4 platform interface by first pressing F4, and then clicking “New” under the File menu. A simply command use of the hot keys Ctrl+N can also be used to open the Wizard.

mql4_wizard

We can see several project options where the trader can make a selection of the project type:

  • Expert Advisor Template: Here, the trader can create an Expert Advisor template to allow for a full automation of technical analysis and trading activity in the forex market.
  • Custom Indicator: Generate a template to be used in writing a custom technical indicator.
  • Script: Generate a template for writing a script – a program for a one-time execution of any actions.
  • Library: Generate a template for writing a library of functions that can be used in various applications.
  • New Class: A new class of functions can also be generated e.g. EA Generate, which is used to generate a ready-made Expert Advisor based on the library, by selecting trading signals, money management and trailing stop algorithms for it.

Now that we are familiar with the MQL Wizard interface, we can now go on to describe the process of creating an EA and an indicator using this interface.

 

Modular Approach to Creating an Expert Advisor

The basic questions that must be answered when creating an expert advisor are as follows:

  1. What trading signals will the EA be responding to?
  2. What type of money management system will the EA use?
  3. How will the EA implement the trailing stop?

These parameters are what the trader will set in the MQL Wizard for it to generate the EA of choice for the trader. Once the EA has been compiled and tested, it will perform trades according to the algorithms set for the trading signals, money management and trailing stops.

common_properties

In the General Properties dialog box, fill in the following fields:

  • Name — the name of the Expert Advisor, which will also serve as the file name.
  • Author — the name of the author or copyright owner.
  • Link — the e-mail or URL of the developer.

The following required parameters are then created by default:

  • Symbol — in the “Value” field you can specify a symbol the Expert Advisor will work on. If you specify “current”, the Expert Advisor will work on any symbol. Thus the symbol of a chart where the Expert Advisor is attached will be used as the work symbol;
  • TimeFrame — in the “Value” field you can specify a period the Expert Advisor will work on. If you specify “current”, the Expert Advisor will work on any period.


Signals Module

In a generated Expert Advisor, information obtained from the signals modules are used by the EA in making trade decisions. At this stage the trader can add up to 64 combinations of signals modules to the Expert Advisor. Identical modules with different settings can also be added.

signal_module

In this dialog fill in the following fields:

  • Name — the name of the Expert Advisor, the same name will be given to the file of the Expert Advisor;
  • Author — the name of the author;
  • Link — the e-mail or website address of the developer.

Below is the list of required parameters created on default:

  • Symbol — in the “Value” field you can specify a symbol the Expert Advisor will work on. If you specify “current”, the Expert Advisor will work on any symbol. Thus the symbol of a chart where the Expert Advisor is attached will be used as the work symbol;
  • TimeFrame — in the “Value” field you can specify a period the Expert Advisor will work on. If you specify “current”, the Expert Advisor will work on any period.

You will not be able to run the Expert Advisor on a symbol or period that is different from the one specified in its parameters. The corresponding message about using an invalid symbol or period is written to the journal of the client terminal.

This window displays the list of already selected modules of signals and their settings. To add or modify settings of a module, click “Add” or “Modify” respectively. The window of parameters of the signal module will be opened as soon as you do it.

 

Parameters of Signal Module

 

In this window you can specify the parameters of the added or modified module of signals:

  • Name — the modified (added) module of signals. The source code files of the modules of symbols are located in the folder /MQL5/Include/Expert/Signal/. If you click on the “?” button, you will go to the detailed description of the module.
  • Symbol — the work symbol, its price data will be used by the module for the analysis.
  • Use current — if this option is enabled, the work symbol chosen for the Expert Advisor will be used as the work symbol of the module.
  • Period — the work period that will be analyzed by the module. If you choose “current”, the work period chosen for the Expert Advisor will be used as the work period of the module.
  • For each module of signals there is a certain set of embedded parameters:
  • Name — name of the parameter;
  • Type — type of the parameter variable;
  • Value — default value of the parameter.

There are two modes of parameter creation. You can switch between them by a double left mouse button click on the icon. If a parameter’s icon is highlighted , it will be available as an input variable of the Expert Advisor. Such parameters can be then used for optimizing an Expert Advisor in the strategy tester. If the icon is grey , it will be set to a fixed value that can’t be changed from the Expert Advisor properties.

Each module of signals has the Weight parameter. This parameter is used for adjusting the weight of signals of a module and is considered at making final trade decisions on trade operations. The detailed description of the mechanism of making trade decisions is given in the Documentation section of MQL5.community.

Trailing

On this step you select type of trailing of the Stop Loss level.

In the “Name” field select one of trailing types from the drop-down list. Files of source codes of these functions are located in the folder terminal_folder/MQL5/include/expert/trailing/.
For each type of trailing there is a certain set of parameters:

  • Name — name of the parameter;
  • Type — type of the parameter variable;
  • Value — default value of the parameter.

There are two modes of parameter creation. You can switch between them by a double left mouse button click on the icon. If a parameter’s icon is highlighted , it will be available as an input variable of the Expert Advisor. Such parameters can be then used for optimizing an Expert Advisor in the strategy tester. If the icon is grey , it will be set to a fixed value that can’t be changed from the Expert Advisor properties.

 

Money Management

Here you select the type of money management for the Expert Advisor.

In the “Name” field select one of types of money management from the drop-down list. Files of source codes of these functions are located in the folder terminal_folder/MQL5/include/expert/money/.
For each type of money management there is a certain set of parameters:

  • Name — name of the parameter;
  • Type — type of the parameter variable;
  • Value — default value of the parameter.

There are two modes of parameter creation. You can switch between them by a double left mouse button click on the icon. If a parameter’s icon is highlighted , it will be available as an input variable of the Expert Advisor. Such parameters can be then used for optimizing an Expert Advisor in the strategy tester. If the icon is grey , it will be set to a fixed value that can’t be changed from the Expert Advisor properties.

After you press “finish” the MQ5 file of your Expert Advisor will be generated. to start using it you need to compile it first by clicking ” Compile” or pressing the F7 key.

The MQL4/MQL5 Wizard uses source codes of appropriate classes of Standard libraries that contain the simple description of all parameters set during work of the MQL4/MQL5 Wizard. In addition to the classes included in the standard delivery of the terminal, you can write your own classes or create derived classes with a required set of functions and then place them in appropriate directories.
Write your own classes in accordance with simple rules and your trade signal, trailing methods or money management modules will be taken by the MQL4/MQL5 Wizard and can be then used for creating robots with a wider set of functions.

 

Creating Indicators with the MQL Wizard

Indicators can also be created with the MQL Wizard, either from scratch or using an indicator template file. After such an indicator template file has been created, it is automatically placed in the relevant “Indicators” directory in the MT4 Build 600 terminal. A trader can select several event handlers that will be added to the template.
The process starts by usng the Ctrl + N hotkey in the MQL environment, after which the option to create an Indicator appears with other functions. In the next step, the following window appears:

indicator_window

The following fields will appear and should be filled:

  • Name — the name of the custom indicator, which will also serve as the file name.
  • Author — the name of the author (i.e. copyright owner)
  • Link — the e-mail or URL of the developer;
  • Parameters — a set of input parameters (external variables) of the custom indicator.

To include the Variables of the “input” class, click the “Add” button. There are three fields which will appear and should be filled out:

  • Name — the name of the input variable;
  • Type — the type of the input variable that is chosen from the list;
  • Initial Value — the initial value of the variable that will be used on default before it is changed manually.

When you click the Next tab, the dialog box which opens will allow the trader to select additional event handlers that will be inserted into the indicator template. All the necessary parameters will also be specified for the selected handlers.

event_handlers

Check against the event handlers to be selected. The type of the OnCalculate() handler, can also be chosen, and this will be added to the template. If you hold the mouse cursor over a handler name, a pop-up help containing extended description of the handler will be shown. To go to the next step, press the “Next” button.

indicator_label

At this stage one should specify the following parameters:

  • Indicator in separate window — this option allows the trader to define whether the indicator is to be drawn in its own separate sub-window or it will be attached to the main chart window.
  • Minimum — specifies the lower limit of the vertical scale of values for the window when the option of drawing the indicator in a separate window is enabled.
  • Maximum — specifies the upper limit of the vertical scale of values for the window when the option of drawing the indicator in a separate window is enabled.
  • Plots — this signifies how the indicator’s data will be drawn on the indicator window.

When adding a line to the “Plots” box one should press the “Add” button, then specify the name, type and color of the line in question. These options should be formed in such a way that they should be selected in a dropdown list format. As soon as the “Done” button is pressed, the project of the custom indicator will be created and the window for writing its source code will be opened automatically.

Attention!
The author’s views are entirely his or her own.

Share.

About Author

Dankra is a forex trader who has played the markets for 7 years. He also trades binary options and spends his free time developing strategies that traders can use to beat the markets. He also codes indicators and EAs for the MT4 platform.