MQL5 Wizard: New Version

MetaQuotes | 29 April, 2011


The MetaTrader 5 terminal continues to improve and acquire new features. The new MetaTrader 5 build 439 contains the updated MQL5 Wizard, which allows creating Expert Advisors based on more flexible trade rules. In this article we describe new possibilities of the MQL5 Wizard and explain the changes in the architecture of Expert Advisors generated using this application.


Background

Originally, the MQL5 Wizard was designed as a handy tool to help traders easily create programs in MQL5. Already in the first version of the MQL5 Wizard, you could quickly create a ready to use Expert Advisor as a set of simple modules, obtaining its source code in MQL5. What's important, you do not need to know the MQL5 language - all you need is read the article Create Your Own Expert Advisor in MQL5 Wizard.

An Expert Advisor generated by the Wizard contains three modules:

Each EA module is based on a certain class and provides plenty of opportunities for modifying the behavior of your Expert Advisor.

The Standard Library includes a set of functionally complete, ready-to-use classes to implement various mechanisms of money management, open position maintenance and generation of trading signals.

This approach allows creating trading robots based on proven and well-functioning modules. You need only to go through a few steps and specify the necessary parameters. But experience shows that even good examples, explaining the principles of writing custom classes, are not always able to help novice MQL5 programmers. 

Another drawback of the previous version of the MQL5 Wizard is that to implement a new slightly modified trading algorithm, you need to write a new class.

With this experience and comments received from users, MetaQuotes decided to create an advanced version of the MQL5 Wizard with even more functions.


A New Concept of Generating Trading Signals

The main stumbling block in the previous version of the MQL5 Wizard was connected with the problems that could occur when creating one's own trading signals. Therefore, when developing the new version of the Wizard, the emphasis was placed on simplifying the creation of combined trading signals based on simple principles.

For this purpose, the following changes have been made to the base class of the trading signals generator (hereinafter referred to as the Signal):

Thus, the decision about entering the market in one direction or another, can now be taken "collectively", i.e. taking into account the "considered opinion" of every advisor.

The Signal "votes" on the direction of price movement on the basis of embedded algorithms of market patterns detection (specific to this Signal). For example, a stochastic based Signal is able to identify a reversal, divergence with the price, etc.

The Standard Library already includes twenty ready-to-use Signals based on various indicators.


A New Mechanism for Making Trading Decisions

The mechanism for making trading decisions by the Signal can be presented in the form of the following key provisions:

The settings of each generated Expert Advisor contains two parameters — the threshold for making a decision to open or close a position (ThresholdOpen and ThresholdClose) which may have a value from 0 to 100. If the strength of a Signal overcomes the threshold value, a decision is made to conduct a trade operation.

The EA created using the MQL5 Wizard consists of three parts the most important of which is the head that contains the module for generating trading signals. Then the processes in the module of signals can be represented as follows:



The figure shows that the Signal module can contain two blocks - a block of market patterns and a block of advisors. The block of patterns produces forecasts from each pattern, after which the strongest one of them is chosen. The forecasts of advisors (other Signals) are multiplied by the corresponding weight and the resulting values are summed up during voting to produce the arithmetical mean forecast. In this case, the Signal module has produced -36.6 = (-100+60-54)/3 for the current situation. This means the Sell forecast with the absolute strength of 36,6.

Consider the decision-making mechanism on two simple examples.

Suppose there is an Expert Advisor with ThresholdOpen=20 and ThresholdClose=90. Signal modules based on MA with a weight of 0.4 and Stochastic with a weight of 0.8 are involved in making a trade decision. Consider two options of obtained trading signals:



Figure 1. An example of market patterns in the chart

The figure shows the market patterns described in the examples:

a) The divergence of the price and Stochastic oscillator is used in options 1 and 2.
b) The price has crossed the MA indicator
from the bottom up - is used in option 1.
c) The price has crossed the MA from up downwards - is used in option 2.


Combining Signals in the EA

To create our own Expert Advisor, it is necessary first of all to decide on what instrument and in what timeframe we will trade. Second, we should select Signals on the basis of indicators that we will use for trading.

We will have the following conditions for our example:

  1. The traded symbol is EURUSD. Our timeframe is M10.
  2. The Signals used:
    • EMA('EURUSD',M10,31) - signals based on an exponential moving average;
    • Stochastic('EURUSD',M10,8,3,3) - signals based on the stochastic oscillator;
    • EMA('EURUSD',H1,24) - signals based on an exponential moving average from a different timeframe;
    • Stochastic('EURJPY',H4,8,3,3) - signals based on the stochastic oscillator from a different symbol and timeframe;
    • IntradayTimeFilter - a filter by time of the day and the number of the day of the week.


Creating a Trading Robot in the New MQL5 Wizard

Expert Advisor's source code is generated using MQL5 Wizard in MetaEditor.

Basic classes of trading strategies are located in terminal_data_folder\MQL5\Include\Expert\. Ready-to-use algorithms of trade signals classes, classes of trailing open positions and classes of money and risk management are located in the Signal, Trailing and Money sub-folders. MQL5 Wizard parses files in these folders and uses them to generate Expert Advisor's code.

Base Classes for MQL5 Wizard

Figure 2. Base Classes for MQL5 Wizard

To launch MQL5 Wizard you need to click "New" on the toolbar or select "New" from the "File" menu (or press Ctrl+N):

Figure 2. Launching MQL5 Wizard

Figure 3. Launching MQL5 Wizard

Then select the type of the program you want to create. In our case select the "Expert Advisor (generate)" option:

Figure 3. Selecting the type of program

Figure 4. Selecting the type of program


Step 1. General Properties of Expert Advisor

Next opens the dialog box, where you can set the general properties of Expert Advisor:

Figure 4. General properties of an Expert Advisor

Figure 5. General properties of an Expert Advisor

Specify the name of your Expert Advisor, the author's name and the link to your web-site in the "Name", "Author" and "Link" fields (respectively).

Expert Advisor also has the following input parameters:

By default, both options are set to "current" (i.e. the Expert Advisor will be tested and will trade on any symbol/timeframe).

But is it always so good? For example, you accidentally run an Expert Advisor set up for intraday trading on EURUSD (moreover, it uses confirmation from a cross pair), on a weekly chart of AUDNZD. It seems nothing good.

Therefore, it would be better to set the necessary parameters. In the next step select the type of trade signals, on which the EA will trade. To go to symbol selection, click "Next".


Step 2. Select the Modules of Trade Signals

Algorithm of opening and closing positions is determined by the modules of trade signals. Trade signals modules contain rules of opening/closing/reversing positions.

An Expert Advisor can simultaneously use up to 64 different (or the same, but with different settings) modules of trading signals.

Figure 5. Parameters of EA signals (beginning).

Figure 6. Parameters of EA signals (beginning).

The Standard Library has ready-to-use Modules of trading signals:

  1. Signals of indicator 'Accelerator Oscillator';
  2. Signals of indicator 'Adaptive Moving Average';
  3. Signals of indicator 'Awesome Oscillator';
  4. Signals of oscillator 'Bears Power';
  5. Signals of oscillator 'Bulls Power';
  6. Signals of oscillator 'Commodity Channel Index';
  7. Signals of oscillator 'DeMarker';
  8. Signals of indicator 'Double Exponential Moving Average';
  9. Signals of indicator 'Envelopes';
  10. Signals of indicator 'Fractal Adaptive Moving Average';
  11. Signals of intraday time filter;
  12. Signals of oscillator 'Moving Average Convergence/Divergence';
  13. Signals of indicator 'Moving Average';
  14. Signals of indicator 'Parabolic SAR';
  15. Signals of oscillator 'Relative Strength Index';
  16. Signals of oscillator 'Relative Vigor Index';
  17. Signals of oscillator 'Stochastic';
  18. Signals of oscillator 'Triple Exponential Average';
  19. Signals of indicator 'Triple Exponential Moving Average';
  20. Signals of oscillator 'Williams Percent Range'.


Figure 6. Selecting signals

Figure 7. Selecting signals

According to our "Terms of Reference", first we choose "Signals of indicator 'Moving Average''.

Configure the necessary parameters (PeriodMA and Method). Double-click on the "Name" field to exclude from the optimization (by default all the parameters of the signal are marked as input-parameters) all parameters except Weight.

Here we need to mention the fields of "Symbol" and "TimeFrame". These fields should be filled in if the appropriate settings of the signal are different from the current parameters. For a signal, the current settings are those of the "superior intelligence" (in this case, of the Expert Advisor).

Figure 7. Configuration of the signal parameters

Figure 8. Configuration of the signal parameters

Add the remaining signals and configure the necessary parameters. For the optimization, leave only the Weight parameter for all signals.

Configuration of signals is completed. Click "Next" to continue.

Figure 8. Parameters of the EA signals (end)

Figure 9. Parameters of the EA signals (end)


Step 3. Select the Module of Trailing Open Positions

The next step is to select the algorithm of trailing open positions (Trailing Stop). Using the trailing allows you to save earned profit.

Configuration of this module is described in detail in the article MQL5 Wizard: Creating Expert Advisors without Programming. In our case we will not use trailing.

Figure 9. Select the position trailing algorithm

Figure 10. Select the position trailing algorithm


Step 4. Select the Module of Money and Risk Management

On the last step you need to select system of money and risk management, which will be used in your Expert Advisor. Configuration of this module is described in detail in the article MQL5 Wizard: Creating Expert Advisors without Programming. In our case we will use a fixed lot.


Figure 10. Select the money management algorithm

Figure 11. Select the money management algorithm

That's it. Click "Finish".


Checking the Created Expert Advisor in MetaTrader 5 Strategy Tester

If all components of Standard Library are present, the code of the generated Expert Advisor compiles successfully. The best set of Expert Advisor's parameters can be found after optimization in MetaTrader 5 Strategy Tester.

For the optimization of the EA, select period from 01.01.10 to 01.01.11, run it in two stages.

The first stage: "Selection of signal weights, thresholds for triggering of entry/exit conditions and trade levels."

Figure 11. Parameters of the Expert Advisor optimization

Figure 12. Parameters of the Expert Advisor optimization

Here is the result of the best optimization run.

Figure 12. Results of the Expert Advisor optimization

Figure 13. Results of the Expert Advisor optimization

We have already got good results (in terms of profit and maximum drawdown). We must not forget that we were "trading" with a fixed lot.

But let's try to further improve the results. For this purpose, we have another signal (we have not yet used its settings). The values found by optimizing the parameters describe a market pattern recognized by the Expert Advisor.

But let's suggest that the resulting market pattern does not always work equally well. Let's try to apply the time filter to the optimization results.

For this purpose, let's optimize the Expert Advisor according to the "Bad hours" parameter of the "IntradayTimeFilter" Signals. The "Bad hours" parameter is a bitmap of 24 bits (the number of hours per day). Every bit of the bitmask uniquely matches one of the hours (number of bits in the mask and the number of hours in a day match). The value of any bit equal to 1 will override any result of a vote if the number of the current hour is equal to the number of this bit (i.e., the hour is considered bad for trading).

To go through all possible combinations of "good" and "bad" hours, we will optimize the parameter from 0 to 2^24-1 (in the natural form 16 777 215) at a step equal to 1.

Figure 13. Parameters of the Expert Advisor optimization

Figure 14. Parameters of the Expert Advisor optimization

As a result of the optimization we obtain 11 665 415. To understand what this means, let's express it in a binary form:

Here are the parameters of the Expert Advisor after all optimizations.

Figure 14. Properties of the Expert Advisor

Figure 15. Properties of the Expert Advisor

The report of a single test with the best parameters is attached. The profit is higher, and the drawdown is lower. It can be concluded that after time filtering, the results of the trading system at the historic period has improved.


Conclusion

Using the classes of trading strategies significantly eases creation of robots for testing trading ideas right in MetaEditor using the MQL5 Wizard. Now the entire source code of Expert Advisor can be constructed based on the combination of ready-to-use modules of the Standard Library or using your own modules.