Optimization is a search for such parameters of the Expert Advisor’s trading system that will ensure maximum profit and minimum risk for the trader. Search is carried out with the help of computer algorithms as accurately and efficiently as possible.
Optimization is usually tailored towards either:
Expert Advisors algorithms, as a rule, do not provide for “human intervention”, thus they have a block for the formation of signals for market entry, exit and money management:
The optimization process allows you to find the effective sets of the Expert Advisor parameters by multiple overruns of their combinations followed by automatic test run of the trading system on the same historical period.
Optimization is a constant, necessary process that allows you to adjust the settings of the automatic trading strategy to changes in market cycles.
The values found at the start, showing positive results, will lose relevance due to the constant shift of market cycles due to:
A trader should understand that there are no measuring systems anywhere in the world that give 100curate readings all the time. Foreign exchange market is no exception to this rule. Optimization is a great advantage that allows you to keep steady income coming.
To preserve the potential of the developed or discovered strategy, it is enough for the trader to periodically update the input parameters of the Expert Advisors. This is a simple process, which was greatly simplified with the development of computer technologies that automate trading in financial markets.
Optimization is the search and selection of quality Expert Advisor settings using computer technologies implemented in MetaTrader 4 terminal. This technology turns finding the best parameters from manual labour that can take many hours into an easy task that can be done in a minute.
The main purpose of optimization is to select the Expert Advisor's output signals and risk management parameters in order to obtain the optimal balance of the maximum financial result, obtained with minimal risks.
Optimization of trading program settings is easy to compare with hacking code lock. To pick such a code manually is virtually impossible, but if you use computer technology, the substitution is accelerated millions of times, thereby allowing you to find the combination, or in case of an Expert Advisor - to find the best set of parameters that will reveal the full potential of the trading program.
At the beginning of the process, the trader must carry out the preparatory stage:
Before starting the tester, the optimization process is enabled by checking the Optimization box, but before starting the trader must set the methods, types and goals of selecting new EA parameters.
Starting the optimization of the Expert Advisor consists of four steps, during which the goals are defined, limits are set, and the step of changing parameters are changed.
In the lower right corner of the Strategy Tester window, click the “Expert Properties” option, in the window that opens, go to the “Testing” tab
On the testing tab, the trader should determine what to focus on:
In this example, the VR Smart Grid Expert Advisor is optimized, the logic of which is to open order grids, so only the first optimization point is suitable for the trader — to set the search for parameters to get the maximum balance increment.
Genetic algorithm significantly accelerates the search for optimal parameters. It gives greater efficiency to the process of finding optimal parameters by comparing EA settings quickly enough, filtering out inefficient packages at the initial stage.
This method is taken from neural networks undergoing “training” on a big data. In order not to limit artificial intelligence in the number of processed solutions of the problem, but at the same time to reduce the response time, use multithreaded calculation, failing branches of which are cut off on genetic basis at the initial stage.
The main advantage of a genetic algorithm — maximum quality of runs in a short period of time. It reduces a huge number of settings variations to 10400. In some cases, when optimizing Expert Advisors, the number of runs can be calculated in billions, and optimization time in millions of hours. It is in such situations that the genetic algorithm is most effective.
The downside of the genetic algorithm is the existing high probability of skipping the optimizer runs at which the best result could be obtained.
In case of Expert Advisor optimization, the algorithm will not bring to the end of the test period the strategy with “losing” parameters at the start.
The Input Parameters tab prompts the user to manage a set of settings variables that the tester can optimize. It is assumed that the trader knows the logic behind the Expert Advisor, the features of its code and the type of incoming settings.
For management settings, pay attention to the unit of measurement of the cell in the “Value” column. It can be in points or percentages, in which case the step value of one can delay the process. If it is about stop loss and take profit, it is better for the trader to choose the step between runs equal to 5 or 10.
Set the optimization limit in the “Stop” column - The number of the stop graph must exceed the number of the Value cell. This is a “cut-off” that defines the parameters of the final run, by reaching those the optimization test will be stopped. When setting these restrictions, the trader must consider the logic of the strategy.
For indicators, the stop number is selected based on the type of strategy, for example, during intraday trading, indicator periods are rarely needed, equal to 30, 50, 100, etc., but such values are suitable for long-term strategy.
It is not recommended to choose a number greater than 100 for money management parameters, nominated as a percentage. As for parameters nominated in points: stops of 100 or 200 points are rare, whereas such numbers can be used for take-profit.
Remember: large and unjustified intervals increase optimization time. Also avoid setting parameters that have no numeric meaning or searching for “functional” settings that don't matter.
In this example, the VR Smart Grid Expert Advisor has many input parameters, but the most important are the following blocks:
Also, the user can choose the period of moving averages that form the Donchian channel and entrust the optimizer to choose the best time for trading.
Selecting checkboxes indicating optimization of only the necessary parameters, select at the start and finish (the “Stop” column) values that differ in a smaller and greater way from the set parameters in the “Value”. It is also necessary to consider their dimensionality when selecting the iteration step.
Other settings regulate functionality - slippage, magic number that does not allow the robot to manage other (manually opened) orders, terminal time settings, etc. All of them have nothing to do with optimization, so they remain unchanged.
The trader has the opportunity to interrupt the optimization test process on each run by setting filter conditions on the Optimization tab, based on the principles of maximum loss or profit. By default, optimal parameters are already set in the tester:
Any value can be turned on or off by checking the box on the left.
In the example of VR Smart Grid Expert Advisor optimisation above, the trader does not have any need to limit the grid on a series of profitable or loss-making trades in a row, as well as the profit level, so we include only loss settings:
After selecting the parameters on the three tabs of the “Expert Properties” option and activating the “Optimization” tester mode on the left, but before pressing the “Start” button, the trader must select the historical period for optimal parameters search.
This is the interval specified by the calendar date in the “Use Date” tester line. When choosing a segment, the trader should adhere to the following principles:
If a trader decides to optimize the parameters for some other reasons, he can choose a segment based on the general recommendations below, which any test should comply with.
After the above steps, check that “Optimization” option is enabled, press the “Start” button to start “runs”. After - proceed to the selection of the trading system with the most appropriate parameters based on the obtained results analysis.
Finding the optimal parameters of an Expert Advisor in the Metatrader 4 tester is performed by many strategy runs on the same historical interval in limits and increments of parameters specified by the user. The most successful ones are displayed on the Optimization Chart and Optimization Results tabs.
The optimization chart axes:
The location of points in the coordinate axis allows you to get a quick visual idea of the profitability of a particular test. To go to the achieved optimal parameters of the highest-yielding runs at the top of the chart, double-click on the chart. This will automatically transfer the trader to the “Optimization Results” tab.
Optimization results are represented by one line for each set of optimal indicators parameters found.
The runs are summarized into a table in the columns of which are displayed:
If the Expert Advisor was tested to achieve the maximum deposit balance — the set Balance parameter on the “Testing” tab (menu — “Expert Property”), the first runs are the best on profit growth. This will be seen in the second column:
The priority choice is the maximum profit with a minimum of trades, based on the principle that each placed order is a risk.
The ideal ratio is 2, when the profit exceeds the loss twice, but the real indicators range from 1 to 1.5. Less than one — loss is higher than profit, the choice of such parameters can lead to loss of deposit.
Based on simple logic, the trader chooses runs with the lowest drawdown.
The last column describes the specific values that the user specified for optimization in the second step in the Input Parameters tab.
Microsoft Excel has many advantages compared to MetaTrader when working with charts. The resulting optimization results can be copied and transferred to Excel.
To do this is quite simple — open the page of the “Optimization Results” tab and right-click anywhere in the table field. In the menu that appears, select the function — “Copy All”.
Start Excel on your computer, create a new file, or log on to an existing file by opening a new worksheet. Unload the contents of the clipboard by hovering the cursor over the upper left cell. You can press Ctrl + V or use the right mouse button again.
Note that after inserting each parameter of changing indicator settings gets its own column. This allows the user to define in more detail the graphical interrelation between columns of profit, profitability, expectation, number of deals, as well as relative and absolute drawdowns.
Each parameter has its own significant influence, for example, period - on the number of trades, stop loss level - on the size of loss, etc. By matching and combining diagrams, the user can visually select the necessary combination of parameters that genetic algorithm “missed”.
The obtained optimization results give a general view and a set of options for trading system parameters. To get a detailed idea of the effectiveness of each set, the trader must test the Expert Advisor.
The tester will “prescribe” the selected package of trading system installations. Note that the selection in the “Optimization” option, which the user set at the beginning of the process, is automatically deselected, the rest of the settings: period and spread - maintain values, but the trader can change them.
After pressing the “Start” button, the standard testing process of the Expert Advisor starts, during which the tester is “amplified” with additional tabs: Results, Graph, Report, and Journal.
It is quite simple to choose the optimal parameters based on the results of runs - the trader should adhere to the rules of the “golden mean” and do not seek to use the Expert Advisor on the first runs results.
Do not stop on testing the first two or three variants of the configuration package — test at least 25%, or even better - 50%, of the obtained optimization results. Save the optimization chart and report for each of them. Perform a qualitatively modeled, visual and numerical analysis of the selected options at the end of the test procedure.
At the last stage, leave a few packages of Expert Advisor settings for the final test of the robot on demo account.
The exact numbers of the Expert Advisor test report will help you to finally select the appropriate set of run parameters. First of all, the trader should pay attention to the profitability of the strategy by dropping out the results with a number below two.
A high percentage of profitable trades is the second important parameter, but only if they are distributed symmetrically for long and short positions. It is also necessary to compare the total results with the number of trades, which should not differ sharply from a certain average for all tested runs.
Profit does not happen without losses, they will be indicated to the trader by the maximum and relative drawdown and this is the last criteria in the general analysis when choosing a particular run.
A trader can make a simple system of assigning pluses to “winners”, in the above criteria, comparing runs on the principle of “more/less”. The settings packs that receive more marks go to the final part of the tests.
The EA operation is not always a fully automatic mode of managing the trader's funds, before releasing the optimized robot to a real account, the trader should check the opening and closing of the robot. orders on a demo account, the quotes and operation of which are completely the same as the real account.
If the strategy is scalable, i.e. it is able to work on smaller timeframes, the trader can use them for a quick additional check of the theoretical results of the report.
To get an objective evaluation the trader should choose a long enough test period (starting from 1000 candles) and follow several key rules:
The final stage of the test will allow you to select the correct set of new parameters of the Expert Advisor.
Files with the *. set extension are ready-made settings of the Expert Advisor, written specifically for the algorithm of a particular robot. They automatically change the current parameters of the trading system immediately after loading.
New settings for a specific Expert Advisor in *. set format can be obtained from the developer or on specialized forums in Presets section. New settings can be set directly to the current version of the Expert Advisor, but for security reasons it is better to check the operation of new templates in the strategy tester or demo account.
Start Metatrader 4 and click the Data Catalog option from the File menu. In the window that opens, log in to the MQL folder and place the downloaded files in the Presets directory.
These Settings are already present in the Presets directory, but additional saving will allow the user to indicate a unique filename
Compare the result with the test version of the Expert Advisor without optimization. In theory, the optimized one should objectively surpass the "vanilla" one or can help the trader find the best combination of parameters.
In any case, testing of “ready-made” presets before applying on a real account is mandatory.
Before optimization, be sure to save the previous settings of the Expert Advisor, marking the period of their validity in the file name. This will help to create an archive of tested parameters on real trading. The EA often returns to the same parameters on different periods - this is due to different historical periods of quotes that coincide in the dynamics of changes.
Comparison of optimized parameters with archived data will help to specify which indicator settings are constant, to determine the most volatile parameters, etc. Such analytics gives the strategy endless potential, a great advantage in the form of choosing from a limited number of options package settings, will determine in advance the need for optimization.
Files with ready-made settings look like a “grail” for many traders. Owners of the Expert Advisor believe that there may be some perfect combination of settings associated with the incredible ability of the strategy to bring a constant, high profit. In reality, presets have the following disadvantages:
Each strategy is focused on a specific timeframe, volatility of quotes, nuances of their display (five or four digits), spread size, slippage and many other conditions, individual for each broker
The tester provides only relative accuracy of the result due to problems with the modeling of quotes, which depends on the completeness of the archive of ticks on the broker's servers.
A trader needs to accumulate and track his own history of optimizations. Constant work with the strategy will help to quickly detect which settings require constant changes and set their boundaries. Further optimization of the Expert Advisor is reduced to the use of a constant set of templates, which will never happen when applying “third-party” preset files.
The need for optimization is determined by the decrease in profit during the EA operation. Before applying the strategy on a real account, after testing the strategy in the tester and checking its operation on a demo account, the trader must set the “reference” parameters for himself: profitability, relative drawdown, percentage of loss-making trades. Deviation of real indicators from these values by 30% is a signal for optimization.
In the long-term operation of the strategy with an acceptable profit result, you should not hope to get “eternal” trading system. The EA can instantly deteriorate the results by significantly increasing the series of loss-making trades. As empirical observations show, the loss of efficiency begins after the Expert Advisor worked for 40% of the historical period used in testing. That is, if the testing took place on a period of 100 days, the Expert Advisor will lose its effectiveness in about 40 days.
Be sure to put the price limits of the maximum and minimum of the Expert Advisor testing period. Exceeding these limits is a signal to optimize the strategy, in 50% of cases the indicators increase sharply the number of false signals when quotes move to untested price values.
Optimization is a necessary and obligatory procedure for adjusting the parameters of the strategy in order to adjust the indicators of the Expert Advisor for cyclical changes of the market. Thanks to the software solutions implemented in the MetaTrader 4 tester, this process is not complicated today.
A trader who has understood the logic of the strategy gets a great advantage by optimizing the same system without wasting time searching for new trading systems. Instead of a long and difficult path of trial and error, you can get an Expert Advisor that constantly generates profit.