How to optimize forex advisor on history
Hello forex traders! On the pages of the blog we have already discussed the preparation of quotes and testing of advisers, now it is time to talk about optimizing advisors. Optimization has both opponents and supporters, with more opponents.
Why is this happening? The process of optimizing advisors is quite multifaceted, in order to correctly optimize an adviser, some knowledge is required that is inaccessible to a beginner due to insufficient experience. Adds oil to the fire an abundance of various information on the Internet, often incorrect or distorted. That is why optimization supporters have so many opponents - people do not know how to use it. In this lesson, I will tell you how to optimize the adviser correctly and, I hope, save some of the newcomers a couple of deposits.
What is optimization?
It is no secret that manual trading systems become obsolete over time and cease to bring the profit that they brought in the past. At the same time, old unprofitable strategies suddenly start to show themselves well. The blame for the cyclical nature of the market, when some trading conditions are replaced by others. The same thing happens with advisers. Market conditions no longer fit the strategy laid down in the algorithm of the adviser and it starts to lose money. What to do in this situation, just remove the adviser and forget about it? Fortunately, in this case, optimization comes to our aid. So what is it? Essentially, it’s just a fitting of the Expert Advisor’s parameters to the current market conditions, adjusting the strategy, adapting it to changing conditions. As traders adjust their manual trading systems to the current market, algo traders adjust their advisers. Change, adaptation - an integral part of the trading process. One who does not change on time is left overboard, such is the life of a trader.
So, we have decided that optimization is still an important and even necessary detail in trading with the help of advisers. In addition, I repeat, you already know how to upload quotes, install Expert Advisors into the terminal and test them, aware of what “sets” or set-files are. Now it is time to open a terminal and carry out optimization. When I talked about testing advisers, I told you about three testing models and their features. I recommend optimizing the advisors according to the "all ticks" model. This is the most accurate model and the likelihood that you will do something wrong will become less. I will give an example of an advisor test on three models for comparing the final results, so that you can clearly see my words:
Model "at opening prices"
Control points model
All Ticks Model
So, I think, now no one will have a question, why is it advisable to carry out optimization precisely according to the “all ticks” model. Notice how much the first option differs from the second and third. The results for the "control points" model may not differ too much from the results for the "all ticks" model. Only in this case is optimization by control points allowed in order to save time. Therefore, you must first run the EA tests in all three modes and, after comparing the results, make a decision.
The “Optimized parameter” position allows you to select the main output parameter by which each run will be evaluated, namely:
- "Balance"- selection is carried out according to the final deposit balance;
- Profit Factor- selection is carried out according to the final ratio of the total amount of profitable transactions to the total amount of loss-making transactions (i.e. profitability, at least, should be more than 1);
- Expected Payoff- selection is carried out according to the final expectation, i.e. average profit per trade. (The mathematical expectation, at least, should not be equal to or less than the size of the spread);
- "Maximal Drawdown"- selection is conducted according to the minimums of the attainable maximum drawdown sizes. In other words, Maximal Drawdown is the largest amount of funds by which the deposit decreased from the corresponding local maximum. In fact, this indicator indicates the real price of risk. For example, if the maximum drawdown exceeds the size of the initial deposit, it is worth thinking hard about revising the size of the deposit.
- "Drawdown Percent"- selection is carried out by relative drawdown, i.e. percentage of maximum drawdown in relation to the size of the current deposit. Using this parameter as the main output is useful when the EA trades in non-fixed lot sizes or, for example, the progressive lot function is enabled.
You may also notice a checkmark opposite the genetic algorithm. If you uncheck, the tester will run away absolutely all possible options for the combination of advisor parameters. At the same time, optimization will most likely take approximately 100,500 years. Fortunately, the terminal has the ability to search for optimal parameters using the genetic algorithm, which allows optimization in just a few hours or days. In principle, for now this is all you need to know, because this checkmark is a topic for a whole separate article.
It is customary to optimize advisors as well as testing with money management off, lot 0.1. To do this, find the appropriate block in the EA parameters and set a fixed lot of 0.1. The table on the input parameters tab contains 4 columns - the parameter itself, its current value, initial value for optimization, step and final value for optimization. What does all this mean? For example, we want to select the optimal stoploss for the adviser over a certain period of time. To do this, we set the initial stop value (start), say, 10 points. We set the final value, for example 60 - with a stop greater than 60, there is nothing to do inside the day. We can ask at least a million, but the choice of these values must be approached wisely, otherwise it will greatly increase the time spent on optimization. And the last step. If we specify step 10, for example, we get the following enumeration of the selected parameter: 10, 20, 30, 40, 50, 60. Here, too, it is worth approaching from the point of view of logic, it makes no sense to set step 1 or step 10 (5). Step 2 is quite suitable, which will also save resources.
But what if there are a lot of parameters?
The more parameters you test at a time, the longer the optimization will take. But there are situations when there are so many parameters that the terminal refuses to carry out optimization and reports this to the log. In this case, it is necessary to divide all the parameters into 4 groups: parameters that strongly affect the result, medium and weakly affecting, not affecting at all. The degree of influence can be determined by trial optimization of a single parameter. Naturally, in the first place, it is necessary to optimize those parameters that strongly affect the results, and then all the others, in order of importance.
This tab also aims to save optimization time. Here you can set your own rules for dropping results, even at the optimization stage itself. For example, limit the maximum continuous number of losing trades to four, and the maximum drawdown to 10 percent. Then in the optimization results only results satisfying these parameters will be displayed.
Selection of a segment for optimization
In principle, this is the main question when optimizing the adviser, and whether you make some money or lose will depend on the correct choice of this segment. It is this moment that is the source of such a large number of ardent opponents of optimization and working with advisers in general.
So here is the approach used by many newbies. A short accessible period of history is taken (often no longer than a couple of months, so that it was not long to wait) and the "start" button is pressed. After completion, the passage that gives the most "dough" is selected. That's it, the set is set to real and the newcomer is preparing a bag for money, often bragging about his “grail”. And then, of course, there is a drain.
This approach is the most common among non-beginners. Two history sections are selected, an optimization section and a forward test section. At the same time, the optimization section is located in front of the forward test section, without breaks in days. As a rule, the first two-thirds of the selected history section are selected for optimization, and the remaining one-third is allocated to the forward. On the optimization site, the best options are selected, and on the forward period, which the adviser has not yet "seen", good settings are selected. The choice of a plot of history is determined at the discretion of the trader. Moreover, the larger the site, the more adapted the settings to various market surprises, the longer it will earn with the same settings, the later the sets will become obsolete. But at the same time, the total profit of the adviser will be less. The shorter the optimization period, the more settings are adapted to a certain period of the market, certain trading conditions, but the greater its effectiveness under these conditions, the greater the profit. You can perform optimization once a week, or you can do it every five years — to whom you prefer. But there is one drawback in the efforts of traders to find the optimal parameters for a short section - you never know for sure when the settings are out of date. You can guess with a set and the whole next week the adviser will trade profitably, and it may happen that on Monday the nature of the market has changed and the adviser will merge all week. Personally, this lottery somehow does not inspire me, and I do not seek to maximize efficiency when optimizing. Instead, I select sets "for years."
In addition, there is an opinion that it is pointless to look further than three years ago. I cannot challenge this statement with facts, but still I choose an optimization period of at least 6 years with a forward test area of at least two. I'm so calmer.
In general, the pursuit of a trend has a right to life, especially if you are a pro and you really manage to predict in time when your settings will stop working.
Often met on the Internet such a voodoo approach, which is presented as an approach for real pros. The plot of history is divided into two equal sections. On each of them optimization is carried out separately, 10-20 variants of successful settings are saved. Then the settings from the first and second sections are compared and those that are approximately similar are taken as optimal. This is complete nonsense, takes a car of time and does not carry any semantic load. Using this voodoo method, you will kill a bunch of hours for nothing and in the end plant your eyesight.
The purpose of the approach is to find universal settings that in the long run will provide stable returns regardless of changes in the nature of the market, volatility, global trend, such settings that will not become obsolete in a week, month or year. In this case, unfortunately, not every advisor is able to pass my tests.
So, suppose we have a piece of history in 15 years (at least 10), say, from 2000 to 2015. We break this piece into the following periods: 2000-2003 is our piece of backward test, 2003-2012 is the optimization period , 2012-2015 - forward test. After optimization, we conduct forward testing as usual, selecting 10-20 most successful sets. After that, we run the selected sets on the backward test site. The results should be similar to those obtained at the forward. Those sets that pass the test remain for further comparison. Next, run the test on the remaining sets on the entire piece of history and select the one whose results are better than the others. As a result, there remains one most adapted set of settings.
How to select sets at the first stage - forward test? Very simple: the most important thing for us at this stage is the form of the balance curve. Ideally, it should be a straight line going from the bottom left to the top right corner. At the same time, it makes no sense to watch all the best sets in a row - often they are almost the same. Selecting from the best sets is only differing in the number of deals.
If real and tester trading is different
So, we got the treasured set files for our adviser. At the same time, it is too early to put an adviser on a real account. It is time to check out our sets on a demo account. In principle, 20-30 deals for one pair will be enough to understand whether the set was a success. In addition, it makes sense to check whether the deals on the demo coincide with the deals for the same period in the tester. To do this, do a test and compare the readings. If the deals are at least approximately the same, then everything is fine. You should not wait for pip-to-pip transactions and second to second, also if some transactions are not enough, it is also not scary. The overall picture is important, the general similarity. In real conditions, the work of the adviser will always be slightly different from the test - by slipping, the adviser did not enter due to a too high spread, then requotes or something else. But the picture should certainly not differ radically! If you see a completely different picture on the test than in real life, then it is useless to optimize such an adviser - no matter what beautiful set you choose, the adviser will still trade in a different way.
Today you learned the basic principles of expert advisor optimization. However, there are many more different chips that I could not talk about in one article. Nevertheless, the knowledge that you got today is quite enough to optimize the adviser working on periods from H1 and higher so that it brings you profit for many years. Optimize the advisors correctly, and then, perhaps, algorithmic trading will become a little more attractive occupation in the eyes of traders.