Download MetaTrader 5

MQL5 Wizard: New Version

29 April 2011, 12:56
MetaQuotes Software Corp.
12
7 807

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):

  • Any Signal (derived from class CExpertSignal) is based on forecasts of "advisors" that give their opinion about the possible price movement. These advisors, in turn, are also derived from the CExpertSignal class, and therefore can have their own advisors. The number of advisors in each Signal can be up to 64.
  • New methods have been added to the CExpertSignal class, which implement "voting" on the direction of price movement. In addition, it contains a new mechanism for participating in such a "vote".
  • To increase the flexibility of making a decision, each Signal involved in the decision-making (do not forget that the "advisors" are also signals), now can receive information from its own (different from the current) market instruments and/or from its own timeframe.

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:

  • Each Signal has its own set of market patterns (some combination of price and indicator values).
  • Each market pattern has a weight value from 1 to 100. The higher the value, the stronger the pattern.
  • Each pattern generates a forecast of price movement in a certain direction.
  • By comparing the forecasts received from the applied patterns, the strongest one is selected, and a forecast is given in the range from -100 to +100, where the sign determines the direction of the predicted movement (negative — the price will fall, positive — the price will rise). An absolute value corresponds to the strength of the found best pattern. This result is sent to the general vote.
  • The forecast of each advisor within the module goes to the vote with the weight factor from 0 to 1.0, which is specified in its settings ("Weight").
  • The outcome of the vote is a number from -100 to +100, where the sign determines the direction of the predicted movement, and the absolute value characterizes the strength of the signal. It is calculated as the arithmetic mean of weighted forecasts of all the advisors of the module. This outcome is a forecast of the Signal, and the absolute value is an indication of how strong the Signal is.

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:

  • Option 1.

    The price has crossed upwards a rising MA indicator. This corresponds to one of market patterns implying price growth, which is embedded in the MA module. Its significance is 100. At the same time, Stochastic oscillator has turned down and formed a divergence with the price. This is a pattern implying price fall, which is implemented in the Stochastic module . The significance of this pattern is 80.

    Calculate the result of the final vote. The weighted forecast, obtained from the MA module, is calculated as 0.4 * 100 = 40. The weighted forecast of Stochastic module is calculated as 0.8 * (-80) = -64. The final forecast is calculated as the arithmetic mean of the two weighted predictions: (40 - 64)/2 = -12. This is a signal to sell with the conditional power of 12. The threshold value of 20 has not been reached. Accordingly, the trade operation will not be conducted.

  • Option 2.

    The price has crossed downwards a rising MA indicator. This corresponds to one of market patterns implying price growth, which is embedded in the MA module. Its significance is 10. At the same time, Stochastic oscillator has turned down and formed a divergence with the price. This is a pattern implying price fall, which is implemented in the Stochastic module . The significance of this pattern is 80.

    Calculate the result of the final vote. The weighted forecast, obtained from the MA module, is calculated as 0.4 * 10 = 4. The weighted forecast of the Stochastic module is calculated as 0.8 * (-80) = -64. The final forecast is calculated as the arithmetic mean of the two weighted predictions: (4 - 64)/2 = -30. This is a signal to sell with the conditional power of 30. The threshold value of 20 has been reached. Accordingly, the result is a signal to open a short position.



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:

  • Symbol (the string type)                            - the symbol the EA is running on;
  • TimeFrame (the ENUM_TIMEFRAMES type) - the timeframe on which the EA is running.

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:

  •  101100100000000000000111 - i.e. the numbers of "bad" hours are 0, 1, 2, 17, 20, 21 and 23.

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.

Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/275

Attached files |
sample.mq5 (8.75 KB)
Last comments | Go to discussion (12)
Michele Bevilacqua
Michele Bevilacqua | 28 Jun 2011 at 15:15

The use of SignalCustom / iCustom would be very great, and powering the use of the wizard for the programmers who want

use Wizard for making EAs, which is a good choice instead of writing the code from zero.

 

But as i can see, it's not an easy matter to make a SignalCustom, because are involved many libraries/include and the

structure of the Wizard itself.

I can suppose that the file to modify in order to add an "iCustom" functionality is in ExpertSignals.mqh,

and of course the custom signal mqh itself, but maybe other libraries are involved.

 

Of course, an article with the example of how to integrate our own's custom signal, would be excellently very helping.

 

Thank you for ay further instructions 

fiddy
fiddy | 4 Sep 2011 at 09:43

Missing Trading Modules 

 

On the website one of the signals is called 'Signals based on crossover of main and signal MACD lines'

When i use MQL5 there this option is not available the only option is 'signals of oscillator MACD'

How do i get these modules 

html { height:100%; overflow:auto; _overflow:scroll; } body { padding:0; color:#626363; font-family:Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size:.8em; height:100%; } div { margin:0; padding:0; } form { margin:0; padding:0; } td { font-size:12px; } th { font-size:12px; } p { margin:0; padding:0; margin-bottom:12px; } input { margin:0; } input.button { font-family:Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size:1em; font-weight:normal; padding:2px; } h1 { margin:0; padding:0; font-size:1.6em; font-weight:bold; } h2 { margin:0; padding:0; font-size:1.4em; font-weight:bold; margin-bottom:5px; margin-top:5px; } h3 { margin:0; padding:0; font-size:1.2em; font-weight:bold; margin-top:6px; margin-bottom:6px; } h4 { margin:0; padding:0; } ul { list-style-type:square; } a { color:#42639C; } a:visited { color:#42639C; } a:link { color:#42639C; } img { border-width:0; }

P_Cherry
P_Cherry | 21 Feb 2012 at 17:02

Hi,

based on the following quotation:

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.


Is it possible to trade on 2 symbols? Based on trading module results, to buy SymbolA and to sell SymbolB simultaneously?

Peter

surubabs Suresh Kakkattil
surubabs Suresh Kakkattil | 10 May 2013 at 08:47

Hi,

i have a doubt in the article, please look at the market one, from were we get the wright is 0.4 and 8.8 from were you get it ?

Option 2.

The price has crossed downwards a rising MA indicator. This corresponds to one of market patterns implying price growth, which is embedded in the MA module. Its significance is 10. At the same time, Stochastic oscillator has turned down and formed a divergence with the price. This is a pattern implying price fall, which is implemented in the Stochastic module . The significance of this pattern is 80.

Calculate the result of the final vote. The weighted forecast, obtained from the MA module, is calculated as 0.4 * 10 = 4. The weighted forecast of the Stochastic module is calculated as 0.8 * (-80) = -64. The final forecast is calculated as the arithmetic mean of the two weighted predictions: (4 - 64)/2 = -30. This is a signal to sell with the conditional power of 30. The threshold value of 20 has been reached. Accordingly, the result is a signal to open a short position. 

 

Thank you

suresh 

Alain Verleyen
Alain Verleyen | 10 May 2013 at 09:10
surubabs:
...

suresh 

  • When citing an article, would you use Quotation format (ctrl+3), you can also use the Pocket tool.
  • 0.4 and 0.8 are the weight of each signal, you have to read the article closely :

The forecast of each advisor within the module goes to the vote with the weight factor from 0 to 1.0, which is specified in its settings ("Weight").

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...

Step on New Rails: Custom Indicators in MQL5 Step on New Rails: Custom Indicators in MQL5

I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.

Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.

Using text files for storing input parameters of Expert Advisors, indicators and scripts Using text files for storing input parameters of Expert Advisors, indicators and scripts

The article describes the application of text files for storing dynamic objects, arrays and other variables used as properties of Expert Advisors, indicators and scripts. The files serve as a convenient addition to the functionality of standard tools offered by MQL languages.

How to create an indicator of non-standard charts for MetaTrader Market How to create an indicator of non-standard charts for MetaTrader Market

Through offline charts, programming in MQL4, and reasonable willingness, you can get a variety of chart types: "Point & Figure", "Renko", "Kagi", "Range bars", equivolume charts, etc. In this article, we will show how this can be achieved without using DLL, and therefore such "two-for-one" indicators can be published and purchased from the Market.