Optimization of Expert Advisors in MT5 in 2020

Content

  1. Information about useful functions in MetaTrader 5 for optimizationИнформация о полезных функциях в MetaTrader 5 для оптимизации
  2. Start optimization and save the results
  3. Analysis of optimization results in Excel, sorting, creating sets
  4. Checking sets in online trading mode, creating custom trading reports and analyzing them
  5. Conclusion
  6. Script and formulas for calculations

Advantages of Expert Advisor Optimization in MetaTrader5

Optimization of Expert Advisors in MT5 is not a complicated process, you just need some knowledge and understanding of the criteria by which you will have to analyze the results in the future.

Benefits of optimization in MT5 from MT4:

  • The ability to save optimization results

This feature will allow you not to start anew optimization every time, but to continue from the moment where you stopped testing the last time.

Even in the event of an emergency, for example, turning off the light, the optimization results will be saved (file platform_data_folder / tester / cache / *. Gen) on the last passed generation and you can resume testing in MT5 after starting the computer. The genetic optimization cache is saved until the optimization settings are changed or until the optimization itself is completed.

Использование-сохраненых-результатов

Using-saved-results

  • Using agents in testing

This thing is indispensable for those who want to get quick optimization results, but their own capacities are not enough, thanks to the MQL5 computing city it is easy and convenient.

картинка 2-включение-агентов-для-тестирования

Enabling-agents-for-testing

What you need to do to use agents in MT5:

  • have an account on mql5.com with a replenished balance

     

  • log in to MQL5

     

  • add mql5 agents

    Картинка Включение-агентов-в-mt5

Picture of inclusion-agents-in-mt5

  • Ability to continue optimization on another computer

When optimizing in MT5, you have the opportunity to export / import the optimization cache file from one computer to another, or send it to a colleague on the Internet to continue optimization in MT5, provided that he has the same advisor as you.

Important!!! The cache files of the performed optimization are stored in the terminal for 30 days, then they are deleted to save disk space.

Therefore, if you want to save incomplete optimization, we recommend exporting the cache file to a separate folder.

Video saving and exporting cache file optimization

  • Obtaining extensive statistics in the context of single testing of the resulting runs

Such as:

Inputs by day, week, month, etc. which will improve trading by controlling the time periods of trading.

And also view such indicators as Sharpe ratio, recovery factor, LR Correlation, linear regression correlation coefficient, etc. More information about the test report indicators can be found in this article.

Общирная-статистика-тестирования

Extensive-test-statistics

Start optimization and save the results

To start optimization, we must go to the navigator (ctrl + N), select the desired tool for testing, by right-clicking on it and clicking “test”.

Картинка Запуск тестирования с окна навигатора

Running testing from the navigator window

Thus, we will go to the testing tab, then to carry out the optimization we need to enter the test criteria and start the optimization.

In the new version of MT5 2019 (build 2136), a start menu for selecting actions has appeared, as well as the ability to set a delay in ms when opening orders and a profit calculation in pips.

Картинка Выбор-вариантов-оптимизации

Picture selection-optimization-options

Optimization settings, what you should pay attention to

  • Using forward testing
  • Choice of an algorithm and optimization criterion
  • Application of agents

Using forward testing makes it possible to reduce the factor of fitting the EA to historical data. When analyzing the results, set files in the results of which, backtesting will coincide as much as possible with the forward test indicators, they will be more likely to get a similar result in real trading.

The choice of an algorithm and optimization criterion is already a matter of choosing each trader, depending on the desired return from the advisor. The following optimization options are available in MT5:

  • Maximum balance
  • Balance + max. profitability
  • Balance + max. expectation expectation
  • Balance + min. drawdown
  • Balance + max. recovery factor
  • Balance + max. coeff. Sharpe

In my tests, I mainly choose the criterion “Balance + max. recovery factor ”.

критерии оптимизации мт5

MT5 optimization criteria

Video – Running optimization and saving the results

There is a lower limit for the number of forward test runs. If the number of best runs is less than 256, then additional best runs up to 256 are selected to participate in forward testing. If the number of all runs is less than 256, then all of them will participate in forward testing.

If genetic optimization is used, then all unique results are involved in the forward passes.

Analysis of results in Excel, sorting, creating sets

After you have completed the optimization in MT5, you can export the files to Excel for further analysis and creation of set files.

This is done as follows, see the picture below.

Экспорт результатов оптимизации

Export optimization results to Excel

Next, we can use filters to sort the desired results and use the formula = A2 & “=” & B2 to substitute values for the set file, for more details see the video instructions.

Checking sets in online trading mode, creating custom trading reports and analyzing them

After we have selected the sets, the most important criterion for their survivability will be testing on a demo account, this testing will be as close to real results as possible.

The essence and sequence of such testing is shown in the infographics.

 

картинка инфографика-отбор-сетов

Video tutorial on creating a custom trading report and selecting set files in Excel

Conclusion

Optimization of Expert Advisors in MT5 has become a really convenient tool that allows you to optimize an Expert Advisor quickly and efficiently. It is worth noting that despite the clear advantage of the MetaTrader 5 platform over MT4, most traders still use the MT4 platform, but after reading this article, I think that many will use MT5, at least to optimize their own or purchased Expert Advisors.

Reference material used to write the article

  1. Test visualization https://www.metatrader5.com/en/terminal/help/algotrading/visualization
  2. Real and generated ticks https://www.metatrader5.com/en/terminal/help/algotrading/tick_generation#tick_mode
  3. Optimizing a strategy https://www.metatrader5.com/en/terminal/help/algotrading/strategy_optimization#visual
  1. Optimization types https://www.metatrader5.com/en/terminal/help/algotrading/optimization_types#criterion
  1. Test report https://www.metatrader5.com/en/terminal/help/algotrading/testing_report
  2. Script for creating a custom report https://www.mql5.com/en/forum/211620/page4#comment_9536093
  3. Library for script work https://www.mql5.com/en/code/16006

Leave a Comment

Your email address will not be published. Required fields are marked *

📨 Subscribe to our newsletter

Scroll to Top

📨 Подпишись на рассылку новостей

Не шлем СПАМ! Гарантия

Subscribe to our Telegram channel
Открыть чат
1
Scan the code
Hello 👋
How can I help you?