Content
- Information about useful functions in MetaTrader 5 for optimizationИнформация о полезных функциях в MetaTrader 5 для оптимизации
- Start optimization and save the results
- Analysis of optimization results in Excel, sorting, creating sets
- Checking sets in online trading mode, creating custom trading reports and analyzing them
- Conclusion
- 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.
Enabling-agents-for-testing
What you need to do to use agents in 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 ”.
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
- Test visualization https://www.metatrader5.com/en/terminal/help/algotrading/visualization
- Real and generated ticks https://www.metatrader5.com/en/terminal/help/algotrading/tick_generation#tick_mode
- Optimizing a strategy https://www.metatrader5.com/en/terminal/help/algotrading/strategy_optimization#visual
- Optimization types https://www.metatrader5.com/en/terminal/help/algotrading/optimization_types#criterion
- Test report https://www.metatrader5.com/en/terminal/help/algotrading/testing_report
- Script for creating a custom report https://www.mql5.com/en/forum/211620/page4#comment_9536093
- Library for script work https://www.mql5.com/en/code/16006