Testing and optimization of EA in Strategy Tester

Testing and optimization of EA in Strategy Tester

MT5 Expert reports and server log files for the bug report
How to install an Expert Advisor and indicators to the MetaTrader terminals
MT5 Expert reports and server log files for the bug report
How to install an Expert Advisor and indicators to the MetaTrader terminals

Description

The article describes in detail the process of testing and optimization of advisers in the Strategy Tester of the trading platforms MetaTrader 4 and MetaTrader 5.

The necessity and demand for this kind of material have long been foreseen.

Many beginners of the trading platforms MetaTrader 4 and MetaTrader 5 do not understand the essence and sequence of actions while working with experts.

Almost every day (without exaggeration), the forum raises questions for beginners – how to install an Expert Advisor in the terminal, how to buy an Expert Advisor in the MetaTrader, what is the optimization, and how to Install it in the MetaTrader 4 and MetaTrader 5 tester, what is a forward test, etc.

The proposed article intelligently answers these questions and allows us to go a little more professionally, on a concrete example, to this fascinating work.

For further, more detailed acquaintance with the testing and optimization processes, as soon as the material is presented, references are given to the accompanying articles and pages of the MQL5-community site.

Metatrader 5: Testing of Expert Advisor in the terminals

Setting up the Strategy Tester:

  1. Select an Expert Advisor from the list.
  2. Set the currency pair for which you will conduct the test.
  3. TF is better to choose M1. ( TimeFrame will be set by the Expert Advisor from its settings)
  4. Date, for example, 1 month
  5. Optimization: Disabled!
  6. Visual Mode

  1. Deposit (Deposit) is better to establish the one from which you will begin your trade. Do not set too small a balance. And also too big!
  2. Leverage exposes the one on which you will trade.
  3. Every tick is based on real ticks!

Setting up an Expert Advisor in the strategy tester

To start testing, press the “START” button. 

To monitor the progress of the test, you can open the Results tab and observe the testing

For Example:

Each of our Expert Advisors can be tested in the Strategy Tester.
For this purpose, in visualization mode, we have added additional controls!!!!
For example:


You can read more about the controls in our article Exp – EAPADPRO

Our dashboard has a unique code that can not be added to the experts that you buy in open source!

You can add our panel as a library.

EAPADPRO EAPadPRO – Information panel for our experts


Example of Using Exp – TesterPad

Example of Using Exp – Averager

After testing, you can view the report and profitability graph and save a detailed testing report from the Expert Advisor.

Metatrader 4: Testing of Expert Advisors in the Terminal

For testing, we chose our universal trading system The X 

The first thing you need to launch a strategy tester:

After opening the strategy tester, you see the Strategy Tester tab 

Fields for setup:

Expert Advisor – From the list of advisers, choose the one you will test. 
Symbol – Symbol for testing 
Model – Testing Model 
For testing, you can choose one of three methods for modeling historical data:

  1. At the opening prices (fast method on the formed bars) 
    Some mechanical trading systems do not depend on the features of intra-bar modeling; they trade on the formed bars. The fact that the current price bar has fully formed, you can find out by the appearance of the next. It is for such experts that this simulation mode is intended. 
    In this mode, the opening of the bar is first modeled (Open = High = Low = Close, Volume = 1), which allows the expert to accurately identify the end of the formation of the previous price bar. It is on this nascent bar that expert testing is launched. At the next step, a fully generated current bar is issued, but testing is not performed on it!
  2. Control points (the nearest smaller timeframe is used) 
    The method of modeling control points is designed for a rough assessment of experts who trade inside the bar. For this method, it is necessary to have historical data of the nearest smaller period (timeframe). In some cases, the data of a lower timeframe does not completely cover the time range of the timeframe being tested. If there is no data of a smaller timeframe, the development of the bar is generated based on predefined wave patterns, as was the case in the previous, third version of the MetaTrader 3 client terminal. 
    As soon as the historical data of the smaller timeframe appears, the interpolation is applied already to these data. However, the existing OHLC prices of the smaller timeframe act as control points. In most cases, the results of testing experts by the method of control points can be taken into account only as estimates and not as final ones. Such results have an intermediate evaluation character.
  3. All ticks (based on all the smallest available periods) 
    This mode allows you to model the price movement most accurately within the bar. Unlike “control points”, the ticketing method uses not only the nearest smaller timeframe but also all available smaller timeframes to generate data. In this case, if for a time range, there are more than one timeframe data simultaneously, the data of the smallest timeframe is used for generation. Just as in the previous method, control points are generated based on OHLC data of the least available timeframe. To generate price movement between control points, interpolation is also used based on predefined templates, so it is highly desirable to have minute data covering the entire test range. A situation is possible when several identical ticks are generated in a row. In this case, duplicate quotes are filtered, and the volume of the last of such quotations is fixed. 
    It is necessary to take into account the very large possible volume of generated data. This can affect the operating system’s consumed resources and the testing speed.

Use Date – The date range allows you to test the Expert Advisors not on all available data, but only on the selected time interval. It is convenient, if necessary, to explore a separate part of the historical data. Limiting the date range can be used not only when testing an expert but also when generating a test sequence of bars (a file of simulated data used for testing). Very often, there is no need to generate data from the whole history, especially in the case of simulation modeling, when the amount of unused data can be very large. Therefore, if the possibility of using a date range was enabled at the first generation of the testing sequence, then bars outside the specified range are not generated but simply overwritten into the output sequence. The data is not excluded from the sequence so that it remains possible to correctly calculate the indicators on the entire history obtained. It should be noted that the first 100 bars are also not generated. This restriction does not depend on the set date range.

To enable the date limit, you must select the “Use date” checkbox and specify the required values ​​in the “From” and “To” fields. After all the settings have been made, you can press the “Start” button and start testing. After you begin testing at the bottom of the window, you can view the estimated time for completing this process. 

Visual Mode – Visualization mode allows the user to monitor the test on a separate terminal graph. When this mode is enabled, a visualization window opens in the terminal, in which chart and deals opened by the Expert advisor (EA) are displayed.

Period – Timeframe for testing. If your Advisor works on bars or indicators, you need to choose the timeframe to be used for real trading. 
Spread – Test spread. In the MT4 Terminal, the spread can only be fixed. You can set this spread in this field. 
Attention: The results will differ from the real account if your real account contains a floating spread. 
Attention: I do not recommend choosing spread = 0 because, as with each test, the spread will be set from the current spread of the broker, which can be floating. 

Optimization – Check this box if you want to optimize the Expert Advisor in the Strategy Tester, but before that, you need to configure the Expert Advisor for optimization. 

Test parameters selection window

Initial Deposit – The initial balance of your account for testing. 
You can specify here the amount that is sufficient for the expert’s work. 
Positions – You can select the type of items that will be opened. You can only select “only Buy” or “only SELL”. If you have chosen “only Buy” – the adviser will be prohibited from opening SELL positions. 
Optimization – block for managing the type of optimization, for example, on balance, profit factor, drawdown. 

Expert settings window:

You configure the expert for testing in this tab. 

Only the Value field can be configured; the remaining fields are only for optimizing the Expert Advisor. 

Attention: Please be careful if your Expert Advisor has indicator settings, and you will watch the test in visualization mode. 

The indicator settings in the Expert Advisor should be the same as the indicator settings on the chart. 

In other words, the Advisor trades on the indicator set in external variables. 

If you decide to put the indicator on the chart, please set it up as it was done in the Expert Advisor. 

Otherwise, you will have a question: 

Why is there no signal on the indicator, and the adviser has opened or not opened the deal .

To start testing, press the “START” button 



To monitor the progress of the test, you can open the Results tab and observe the testing

For Example:

Each of our Expert Advisors can be tested in the Strategy Tester.
For this purpose, in visualization mode, we have added additional controls!!!!
For example:


You can read more about the controls in our article Exp – EAPADPRO

Our dashboard has a unique code that can not be added to the experts that you buy in open source!

You can add our panel as a library.

EAPADPRO EAPadPRO – Information panel for our experts


Example of Using Exp – TesterPad

Example of Using Exp – Averager

After testing, go to the “Reports” tab to view the results of testing your Expert Advisor in the Strategy Tester.

In the “Graph” tab, you can observe a graph of the balance and equity changes during the testing period.

To save the test report, go to the “Results” tab and right-click on the data. You will see the menu for saving the report:

MetaTrader 5: Setting the optimization and saving the file SET

Our advisors have the same algorithm of signals and functions.

However, because of the differences between the terminals MT5 and MT4, there may be errors in performance.

The strategy tester in the MT5 terminal, at the moment, is the most technologically advanced and accurate.

The most important feature of the terminal MetaTrader 5 and Strategy Tester is the ability to test on real ticks. The spread and stop levels in the MetaTrader 5 are floating. This means that testing in the MT5 strategy tester is as close to live trading as possible.

We will not explain testing and optimization in the MetaTrader 4 terminal! You already know how to test it. The optimization process is similar to the process mt5 (Settings and Startup)

But the main feature of the strategy tester from MT5 is, of course, the ability to optimize in the cloud MQL5 Cloud Network.

The cloud allows optimizing the Advisor for thousands of other computers at a minimal price. It’s very cheap and fast. Therefore, I highly recommend using MQL5 Cloud.

In the archive with the Expert Advisor, you will find several files with a set for optimization. These are just examples, but they will show you how to configure optimization.

Remember: Each currency pair and broker have their trading conditions (Spread, swap, commission, settlement method, execution, account type), so the optimization results may differ!

To make the results more and less similar, you need to turn off Random Delay. To optimize, it is not required!

You can download our files for optimization for The X

To optimize an expert, you need to open Optimizer MT5 :

Select the Complete mode Optimization (new version of the MetaTrader 5 terminal)

After that, we have to adjust our Strategy Tester for optimization:

  1. Choosing an expert for optimization.
  2. Selecting the trading symbol (currency pair) that we want to get results.
  3. Timeframe (Our expert can optimize the TF of each indicator, so skip this step)
  4. Period optimization (can be optimized over the last year; it makes no sense to optimize for over 10 years!)
  5. Be sure to choose a model: “Every Tick is based on real ticks”!
  6. Choose the type of optimization = Exhaustive search parameters ( Slow complete optimization )
  7. Go into setting input parameters Inputs.

Load your file to optimize or configure the settings to your liking!

Click the right mouse button – Load (Load)

We choose the path where you saved our files and select the file with the number of digits in price from your broker (4-digit or 5-digit broker)

Configuring parameters optimized:

After loading, you will see our optimization options

  1. Check or uncheck those options that you want to optimize. (By default, I have set up the file so that you can optimize all the important parameters)
  2. Start (Start) – The initial value of the parameter to optimize.
  3. Step (Step) – a step change in the parameter at each run of the optimizer.
  4. Stop (Stop) – The final value of the parameter to optimize.
  5. Click Start to begin the optimization! It can take anywhere from 1 hour to 1 week! You can also use the cloud to optimize customer!
  1. Remember! The more parameters and steps to optimize, the more time is needed to complete the testing and optimization!
  2. Value (Value) – This is a fixed value. The Advisor will take this value if this parameter is not optimized. Or testing!

Enable cloud optimization

I highly recommend including cloud OPTIMIZATION!

In this case, I turn off the work of my processor. So my computer does not slow down when optimized. And the cost of one pass in the cloud is less than 0.01 cents!

Press the START button and go on your business!

Selection results and save the file “.Set”

After we receive the results of the optimization, we can choose the options you want and save the file Set to use them in the future.

  1. Go to the tab of optimization (Optimization results)
  2. Choose the desired result
  3. Run a single test
  4. Look at the result:

After that, go to the Settings tab 1 ( Inputs ) and save the SET FILE 2 (Click the right mouse button)

Save the settings file where you store all your important files!

Loading configuration file (Set File) in our expert on real chart:

Once you’ve found your settings and the result of the optimization is large enough, you can download an expert with these settings for the job.

Remember! Optimization is a coarse setting method of search and optimization results can not guarantee future profitability in real time!

I recommend to check the system first on a demo account with your broker these settings.

After that, you can open a cent account or a small deposit for verification.

It was only after extensive testing, you can trade on large deposits!

  1. Download our expert on the chart.
  2. Go to the tab Settings (Inputs).
  3. Click LOAD (Load).
  4. Open the folder where your files are stored in settings.
  5. Select a file and click Open.

If you did everything correctly, then the graph will show our panel EAPADPRO with a green smiley!

If you have something not installed or installed incorrectly, you can read the options refusal to trade adviser: EAPADPRO Do Advisor work?

Multicurrency testing and optimization in the MetaTrader 5 terminal

After these actions, I recommend checking these settings on other currency pairs. To do this, in the market review, I added only those currency pairs that I think are the main ones and that you can trade:

Customize the optimization by symbols:

Run the optimization and get the results:

These actions are aimed at finding universal parameters for the Advisor to use on any currency pair.

As you can see from the results of optimization for currency pairs. This set of settings gives a good result in only 4 currencies out of 11!

MetaTrader 4: Setting the optimization and saving the file SET

You can download our files for optimization for The X

Note: Terminal Strategy Tester of MetaTrader 4 is not accurate and does not include floating spread and delay performance, so its results are exemplary!

To optimize an expert, you need to open Optimizer MT4

After that, we have to adjust our Strategy Tester for optimization:

  1. Choosing an expert for optimization.
  2. Selecting the trading symbol (currency pair) that we want to get results.
  3. Be sure to choose a model: “Every Tick”!
  4. Period optimization (can be optimized over the last year; it makes no sense to optimize for over 10 years!)
  5. Timeframe (Our expert can optimize the TF of each indicator, so skip this step)
  6. Set the tick on Optimization ( Optimization )
  7. Go into setting input parameters Inputs.

Load your file to optimize or configure the settings to your liking!

Click the right mouse button – Load (Load)

We choose the path where you saved our files and select the file with the number of digits in price from your broker (4-digit or 5-digit broker)

Configuring parameters optimized:

After loading, you will see our optimization options

  1. Check or uncheck those options that you want to optimize. (By default, I have set up the file so that you can optimize all the important parameters)
  2. Start (Start) – The initial value of the parameter to optimize.
  3. Step ( Step) – a step-change in the parameter at each run of the optimizer.
  4. Stop (Stop) – The final value of the parameter to optimize.
  5. Click Start to begin the optimization! It can take anywhere from 1 hour to 1 week! You can also use the cloud to optimize customer!
  1. Remember! The more parameters and steps to optimize, the more time is needed to complete the testing and optimization!
  2. Value (Value) – This is a fixed value. The Advisor will take this value if this parameter is not optimized. Or testing!

Selection results and save the file “.Set”

After we receive the results of the optimization, we can choose the options you want and save the file Set to use them in the future.

  1. Go to the tab of optimization (Optimization results)
  2. Choose the desired result
  3. Apply settings for testing.

Run a single test:

  1. Look at the result:

After that, go to the Settings tab ( Inputs ) and save the SET FILE

Save the settings file where you store all your important files!

Loading configuration file (Set File) in our expert on real chart:

Once you’ve found your settings and the result of the optimization is large enough, you can download an expert with these settings for the job.

Remember! Optimization is a coarse setting method of search and optimization results can not guarantee future profitability in real time!

I recommend to check the system first on a demo account with your broker these settings.

After that, you can open a cent account or a small deposit for verification.

It was only after extensive testing, you can trade on large deposits!

  1. Install our expert on the chart.
  2. Go to the tab Settings (Inputs).
  3. Click LOAD (Load).
  4. Open the folder where your files are stored in settings.
  5. Select a file and click Open.

If you did everything correctly, then the graph will show our panel EAPADPRO with a green smiley!

If you have something not installed or installed incorrectly, you can read the options refusal to trade adviser: EAPADPRO Do Advisor work?

MetaTrader 4: Optimization results

Optimization in all parameters can be done in 2-3 days.

It’s long enough, but you’ll get the results of all the passes.

For more than 20,000 passes, we spent about $ 6 on optimization. You can adjust the number of passes, limiting the number of optimization parameters.

When writing the article, we will follow the examples.

Let’s say we got results on our optimization.

We select the Profit column and sort the results by the largest profit.

You can conduct a single run of results to form a complete report on the items.

After the testing is completed, we will get results with which we can agree.

And if they suit us, then We can save the settings!

Remember: Test results are only 99% true. On real accounts, you may have delays in the execution of orders, slippage, power outages, and other factors.

MetaTrader 4: Optimization of Expert Advisors

Configure the terminal for optimization and make sure to checkmark  “Optimization.” 
After that, open the Expert Advisor settings and configure the fields for optimization:

Start – The start value of the parameter that you want to optimize. 
Step – The step of changing the value of the parameter that you want to optimize. 
Stop – The final value of the parameter that you want to optimize. 
Be sure to checkmark the parameter that you are going to optimize. 

For example:

This means that we want the StopLoss and TakeProfit to be tested from the initial value of 100 points, with a step of 100 (100, 200, 300, 400 ….) and a value of 600 
In total, the optimizer must pass 6 * 6 passes = 36 results. 

You can see the optimization results in the “Optimization Results” tab.

After optimization, you can look at the 3D optimization chart:

If you want to get a report on the tested values ​​and the result of optimization, you need to select the right results with the right button and press the “Set Inputs Parameter ” button. After that, you can click the “START” button again and get the full test report. 

To save the set of settings you have tested, you need to open the parameters of the Advisor in the strategy tester and click the “SAVE” button.


You can download these settings to your Expert Advisor on a real chart. 


Testing and optimization in MetaTrader 5 (OLD)

FAQ: Question-answer

1. Why are the results of the tests the same name different in other Brokers?

– Different quotes explain different test results in other Brokers. Each broker has its quotation providers. Therefore, there is a difference in the test results.
– Each broker has its spread and its specification of constructs, so the results may differ drastically.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.
Read more