Русский 中文 Español Deutsch 日本語 Português 한국어 Français Italiano Türkçe
MQL5 Wizard: New Version

MQL5 Wizard: New Version

MetaTrader 5Trading | 29 April 2011, 12:56
21 135 16
MetaQuotes
MetaQuotes

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 Ltd.
Original article: https://www.mql5.com/ru/articles/275

Attached files |
sample.mq5 (8.75 KB)
Last comments | Go to discussion (16)
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...

yamarkets1
yamarkets1 | 20 May 2018 at 11:34
Thank You...for the answers...also i want to trade in forex in Yamarkets using Meta Trader 5.
Longsen Chen
Longsen Chen | 23 Aug 2020 at 04:37

Hi,

I have a question.

In tab Overview, I see 'Complete optimization', 'Generic optimization' and 'Forward optimization', which one do you suggest?

I downloaded your code of sample.mq5, compiled it and set up all the input parameters for optimization as indicated in Figure 12. 

I chose 'Complete optimization' and lauched 'Start'. 

Unfortunately I got message in 'Journal'

2020.08.23 05:25:54.552 Tester register MQL5.community account and use MQL5 Cloud Network to speed up optimizations

2020.08.23 05:25:54.562 Tester optimization by "Custom max" criterion not started, no OnTester function in "MQL5\Experts\Ksana\sample.ex5"

It seems your code missing OnTester.


George

Longsen Chen
Longsen Chen | 23 Aug 2020 at 05:24

Hi

After I posted, I found out the answer to my question.

I carefully fill in the tab 'Settings'.

The timeframe has to be the same of the code -- M10

Date changed to 2018.1.1 - 2019.1.1

Optimization is selected to Slow complete optimization and balance max.


George

farhadmax
farhadmax | 11 Jul 2023 at 00:24

Hi, I read this article two times.It is a little bit complicated, maybe its better to write another article, anyway.


and previously, I had read this article : https://www.mql5.com/en/articles/226 which explained how to write a signal module ourselves.


my question specifically is:

with the introduction of these new stuff ( I mean, voting an threshold stuff), has anything changed about creating a custom signal module (which is explained in this article: https://www.mql5.com/en/articles/226) ?

I learned how to write a custom signal module, but with the introduction of these new stuffs (voting, threshold and ...) I'm not sure whether anything has changed about creating a custom module or not

Statistical Estimations Statistical Estimations
Estimation of statistical parameters of a sequence is very important, since most of mathematical models and methods are based on different assumptions. For example, normality of distribution law or dispersion value, or other parameters. Thus, when analyzing and forecasting of time series we need a simple and convenient tool that allows quickly and clearly estimating the main statistical parameters. The article shortly describes the simplest statistical parameters of a random sequence and several methods of its visual analysis. It offers the implementation of these methods in MQL5 and the methods of visualization of the result of calculations using the Gnuplot application.
Using MetaTrader 5 Indicators with ENCOG Machine Learning Framework for Timeseries Prediction Using MetaTrader 5 Indicators with ENCOG Machine Learning Framework for Timeseries Prediction
This article presents connecting MetaTrader 5 to ENCOG - Advanced Neural Network and Machine Learning Framework. It contains description and implementation of a simple neural network indicator based on a standard technical indicators and an Expert Advisor based on a neural indicator. All source code, compiled binaries, DLLs and an exemplary trained network are attached to the article.
MQL5 Wizard for Dummies MQL5 Wizard for Dummies
In early 2011 we released the first version of the MQL5 Wizard. This new application provides a simple and convenient tool to automatically generate trading robots. Any MetaTrader 5 user can create a custom Expert Advisor without even knowing how to program in MQL5.
How to Order an Expert Advisor and Obtain the Desired Result How to Order an Expert Advisor and Obtain the Desired Result
How to write correctly the Requirement Specifications? What should and should not be expected from a programmer when ordering an Expert Advisor or an indicator? How to keep a dialog, what moments to pay special attention to? This article gives the answers to these, as well as to many other questions, which often don't seem obvious to many people.