Hello to all algorithm traders! On our blog, we recently discussed automated trading systems and it's time to talk about Expert Advisor optimization.
There are usually 2 opinions on the optimization of Expert Advisors, some traders that this is a waste of time and optimization only harms the trading system, others see more opportunities in it. The thing is that the process of optimizing advisors is quite multifaceted, and without sufficient experience a trader can easily get confused, make mistakes and, as a result, not get the desired result. In this article I will tell you how to properly optimize the EA and achieve maximum results.
The idea of optimization in enumerating the parameters of the advisor to obtain the best indicators of profitability and drawdown. Of course, you can manually change the settings of the robot and run them in the tester, but it is much more convenient to do this by optimizing the parameters. The MT4 and MT5 Strategy Tester has functionality that will allow you to select any values of the Expert Advisor and compare the results. Upon completion of the optimization, you receive a report on the performance of the trading system when certain parameters are used. In addition, after testing any of the parameter options, you get a full report with deals and trade statistics for the selected period of time, which can contain very useful information for further optimization.
You should be aware that manual trading systems become obsolete over time and no longer profitable as they used to. At the same time, old losing strategies suddenly start to trade successfully. It's all about the cyclical nature of the market and changes in volatility, when market conditions no longer suit certain strategies. The same thing happens with many advisors. When you optimize your strategy on history, you practically find the best settings for that particular time period, and it is not at all necessary that these settings will work just as well in the future. In practice, such “optimal” settings can start to bring a loss literally after a few weeks and it is impossible to determine when the settings will become irrelevant and need to be optimized again. This is the point of view of opponents of optimization. But if you look at it, it is not the optimization that is to blame, but the trading strategy itself or the optimization and the father-in-law were done incorrectly. Now we will try to figure out how to do the optimization correctly.
The testing and optimization model refers to the quality of the quotes on which the tests will take place. For the best results it is important to use the most accurate quotes, therefore we choose only the “every tick” model. There is a “control points” and “open prices” model, but this is a very rough option for testing and can be misleading for a trader, because it often performs better on tests than the “every tick” model. In practice, tests on such quotes are rather poor quality and there is no point in using them.
I would like to note right away that in MT4 the quality of quotes is lower than in MT5, as well as the speed and information content of testing. However, this is an equally worthy platform for optimization, and further work will be described in MT4.
The "Optimized parameter" option defines the main output parameter by which each cycle of optimization tests will be evaluated:
Be sure to use the Genetic Algorithm option. It allows you to search for optimal parameters using a genetic algorithm that will complete the optimization in just a few hours or days. Otherwise, the tester will run all possible combinations of the advisor's parameters and this may take about googol years.
In order to optimize any parameter, you need to mark the checkbox and specify the values for optimization. The table on the input parameters tab contains 4 columns - the parameter itself, its current value, the initial value , the step and the final value for optimization. The " current value" does not matter for optimization, it is the value that is used in the EA for single testing or directly for trading.
The optimizer uses values from the Start, Step, and Stop columns. Suppose we need to find the optimal stop loss. To do this, indicate the initial value of the stop loss (start), for example, 50 points, then enter the final value, for example 200, after that set the step to 10 points. As a result, the optimizer will check on history all stop loss values from 50 to 200 with a step of 10, i.e. 50, 60, 70, 80 ..., 200 and will give a table with the results for each run.
The more parameters you test at once, the longer it will take for the terminal to complete the optimization. For example, you want to optimize one EA parameter with values from 20 to 100 in increments of 20, which means the optimizer will make 5 runs (20, 40, 60, 80, 100). The terminal will cope with this in a couple of seconds, but what if we optimize 2 or more parameters at once? It all depends on the number of runs for each parameter, if, for example, you want to optimize 3 parameters at once with the number of runs for the first parameter 5, for the second 10, and for the third also 10, then you will need only 500 runs on history to complete such an optimization. Just multiply the number of loops for each parameter to get the final number required.
It happens that there are too many parameters for optimization and MT4 simply freezes. In this case, you need to determine the parameters for importance and connectivity and optimize them separately. For example, you should not test the take-profit values and the values of the stochastic parameters together. If you have a poor idea of the degree of influence of individual parameters, you can determine this by trial optimization of a single parameter.
General recommendation - optimize together those parameters that are related to each other, for example, the parameters of the indicator used by the advisor or the parameters of stop loss, take profit and trailing stop.
This tab will help you save time when optimizing, but only if you already have experience and a good understanding of the whole process. You can set conditions for filtering results, for example, limit the maximum continuous number of losing trades, maximum drawdown, etc. As a result, the optimization results will contain only those results that correspond to these parameters.
This is one of the important criteria when optimizing an advisor and your profit from trading with this advisor will depend on the correct choice of this period of time. That's where novice traders constantly make mistakes and often become opponents of optimization and working with advisors in general.
The beginner's approach
A beginner trader usually takes a short available history period (often no longer than a couple of months so that there is not a long wait) and presses the "start" button. After completion, those settings are selected that give the most profit. That's all, the robot is launched on a real account with such parameters, and the trader already imagines how he buys a new Ferrari. And then, of course, it drains the deposit. The mistake is that optimization for such a short period of time is absolutely useless and will almost always give erroneous results.
Advanced approach
Already experienced algo-traders do, in addition to back tests, forward tests. Simply put, a back test is a testing option when you can check the selected settings only on live trading, because the parameters were selected on the last available quote history. Forward test is an option in which optimal settings are selected and checked on the quote history that follows optimization, i.e. the advisor has not seen these quotes yet. This is a much more efficient method and allows you to check the stability of the system.
So, for forward tests, two history sections are selected, an optimization section and a forward test section. Of course, the optimization section is located before the forward test section. Usually, the first two-thirds of the selected history period is chosen for optimization, and the remaining one-third is used for the forward. The longer the time frame, the more adaptable the settings will be to various changes in the market, and the longer it will earn consistently. I recommend using it for at least three years, and preferably more. It is also important that the market changes several times during the selected time period, you can see this on the weekly or daily charts.
Once you've got the best EA settings, don't rush to launch the robot on a real account. Check your sets on a demo account, 20-30 trades will be enough. Make sure that the trades from the test match with the demo for the same period. If the deals almost coincide though, then everything is fine. Do not expect trades to be 100% the same, there will be differences due to spread, slippage, or simply because the broker was unable to execute a trade order for any reason. But if the result on a demo is fundamentally different, then most likely the matter is in the trading system itself or the broker has unsuitable trading conditions for it.
The higher the timeframe you use, the more the results will coincide with the demo and even with a real account. If the system trades on a timeframe from H1 and higher, and also uses stops from 200 - 300 pips, then the system will behave almost like in the tester, because slippage and spread changes will insignificantly affect the result. But if you have a scalper with a take profit of 10 pips, then the system, in the best case, will work only on demo.
As you can see, optimization of the EA parameters has many nuances, but it is not as difficult as it might seem. There are many more secrets that I could share with you, but this is material for other articles. I wish you success and stable trading with your advisors!