Testing and optimization of expert advisors are two important functions of Meta Trader 4 forex optimization.
The process of choosing the optimum parameters for expert advisors is known as optimization.
Generally a trader will improve, or optimize, the input parameters of their robots to minimize risk while maximizing their profitability.
Meta Trader 4 applies a number of different input parameters in automatic mode when it conducts expert advisor optimization which is a multiple testing process.
Although the simple form of optimizing is no more complicated than altering the parameters of the expert advisor to mirror history in line with earlier price movements and market conditions.
But it you set up your expert advisor to trade real time using the results of the optimization using historical data because you had good results at the stage then your results in real-time trade would be very different.
This is because real optimization did not take place, only an adjustment of parameters.
For forward testing, or expert advisor optimization to be correct and qualitative it must include both of these stages.
A specific segment of history known as a test or historical period is to be used as the first stage to optimize (or adjust) the expert advisor.
The results of the adjustment are presented in a table in the form of expert advisor input parameters.
Taking the most effective parameters, a robot will be set up to 'trade' using a new segment of time that has not been adjusted and does not know how to operate..
This period is called a forward period. If an expert advisor shows good results (it is no longer optimization!) on this segment, it means you can use this expert advisor for trades on a real account.
Test and forward periods differ for expert advisors working on different timeframes.
The following are what is recommended as forward and historical time periods for expert advisors and timeframes:
* The forward period of 6 months and historical period of 2 years is recommended for H1
* M30 has a recommended forward period of 4 months and historical period of 1.5 years.
The forward period of 3 months and historical period of 1 year is recommended for M15.
Smaller timeframes are not recommended for testing expert advisors. To get a better understanding of forward and historical segments look at the next picture:
As an example, we take today's date as being 30th November 2011 and choose to optimize the expert advisor using the M1 period taking a historical segment of 1 year and a forward time period of 3 months.
So the historical period ends at 30th August 2011 and starts at 30th August 2010.
We can now go into greater detail with the expert advisor testing and optimization process.
Let's adjust the Strategy Tester.
The strategy tester is opened in the menu of the trading terminal. We go into the 'View' section and select which expert advisor we are going to optimize using the 'expert advisor' tab.
From the drop-down menu choose the currency pair to be used from the 'Symbol' list box.
'Model' - open prices only. Now select the period that has the optimization settings by ticking the 'Use date' box and pick out the time period to test the advisor.
The next step is to download a currency rate archive.
The rates that Meta Trader 4 users have access to have a 1 minute minimum.
The data download settings should be adjusted before the rates are downloaded.
The process for this is to go to 'Tools', 'Options' then go into 'Charts', set the highest possible values in the 'Max bars in chart' and 'Max bars in history' fields.
The rates should then be downloaded by clicking on 'Tools', 'History Center', 'Symbols', 'Currency Pair, 'Period' and the picking out a time period and currency pair.
You should note that dealing centers will not offer up any modeling quality in excess of 90% (and 90% is an ideal variant).
This is due to data being downloaded form MetaQuotes servers that will frequently offer archives that have missing rates for large time periods sometimes even months.
Look at the picture below for an example of a missing period between 10.06.2011 and 22.09.2011. 3 month are missing!
How would a trader be able to make qualitative expert advisor optimizations if they can't work with anything?
The results when modeling under these circumstances will be nothing like 90% and more like 40%.
Luckily there is an answer to this problem. You can download full archives with the tick rates that give you modeling quality results of up to 99% from the DukasCopy dealing center website.
The next stage is to load up the optimization file into the strategy tester assuming you have one.
If you don't have one then you should load the expert advisor configuration file, which was copied to the folder of the trading terminal.
This will be found in :Program Files/MetaTrader/experts/presets/ or the folder :Program Files/MetaTrader/experts/presets/advisor name/.
To do this, open 'Expert properties', go to the tab 'Inputs', click 'Load' and choose the optimized expert advisor (extension *.set) file with the corresponding instrument and period (timeframe).
The expert advisor will have initial parameters loaded which you should change on the 'Inputs' tab.
The way to change them is to tick the items in the column called 'variable' as part of the expert advisor optimization process.
Set start, stop and step values in the corresponding columns, and then save the expert advisor optimization file to the folder :Program Files/MetaTrader/tester/.
This is the default folder, which is opened when you press 'Save'.
If you optimize several advisors at once, it is a good idea to create a folder and name it the same as an expert advisor, in the folder /tester/, and save the initial optimization file to that folder.
This approach will help ensure you don't get confused as you will be able to easily match up the optimization file with the expert advisor.
You should also include the name of the timeframe and currency pair in the name of the optimization file, for example; 'optimization_advisor_name_ eurusd_m15.set'.
Then we go to the tab 'Testing', where we set an 'Initial deposit' value, a position (Long or Shot), choose an optimized parameter (Balance by default) and tick off the 'Genetic algorithm'.
The genetic algorithm is used to study the parameters so discarding any that are identified to be unprofitable which reduces the amount of time needed and the number of variants.
To finish press 'OK'.
The launch of an expert advisor optimization.
Immediately before the launch of the expert advisor parameter optimization is launched the optimization check box should be ticked.
You can press 'Start' when this has been done.
When testing a forex expert advisor the test period can last several minutes, hours or days.
It all depends on the amount of parameters that each expert advisor has optimized.
Once optimization has been completed a graph is formed on the 'Optimization graph' tab showing the expert advisor parameters that are more profitable in a darker color.
Any work with charts should be combined with 'Optimization Results' table analysis so the input parameters can be clearly seen.
You would be wasting your time to check all of the parameters and just searching through the best ones as the bulk of them are identical.
You'd also waste too much time checking hundreds of combinations.
A better way would be to sort them out by profitability and then check the combinations that had the best results.
The way to do this is to right click on a line that has a combination of maximum profit and choose 'Set Input Parameters'.
When the tester window opens up you should then have the option to change the 'model' parameter.
Set the value to 'Every tick' instead of 'Open prices only', as testing results according to every tick will be more precise.
The algorithm of your expert advisor will be a factor here. Ones that use open prices will show incorrect results if the tests are done using every tick!
That is why before optimizing an expert advisor, you should understand its operation logic. The 'Optimization' check box should be unticked and 'Start' should be pressed when you want to test the expert advisor with input parameters that are optimized over the test period.
The test analysis is completed with the use of the 'Report' and 'Graph' tabs. You can tell that the input parameters are better the more ascending and smooth the profit chart is.
So should a chart show a line that is broken and has a descending movement as opposed to an ascending one then the input parameters aren't acceptable so should be discarded.
However, you should remember that if you performed testing and optimization of an expert advisor using MetaQuotes rates, it would be very likely that such a chart was as a result of missing data for a certain time period.
So this chart should not be used to make judgments about input parameters.
You can refer to the 'Report' tab of the Meta Trader 4 platform strategy tester for better information about perception and analysis. You will see the following once you have opened the tab:
Then we use various combinations of input parameters in turn, sorting them by different parameters.
You should pay close attention to parameters such as 'Number of trades' (which can differ per expert advisor) and 'Maximal and minimal drawdown' when choosing combinations.
An expert advisor should be tested on a forward period when a good ascending chart with successful results such as small drawdown, good profit emerges with a different set of parameters.
Using a forward period when testing an expert advisor. Find the 'Settings' tab and set some dates for the end (To) and beginning (From) of the forward period as opposed to the historical period time interval.
This forward period will start up from the end of the period that is historical and will use today's date to end.
Pressing 'Start' will launch the robot testing using the input parameters given as received at the first stages of the optimization.
If good results appear on the forex optimization (according to the graph and the report) this combination of parameters can be saved.
You can do this by opening up the 'Settings' tab and clicking on 'Expert properties'. You will see the familiar window with the input parameters that showed good results.
Press 'Save'. You can save a file to the folder with .set files already available, naming it so that you could understand what expert advisor, currency pair and timeframe this optimization file has.
As you may have some good results appearing many times throughout testing the expert advisor using differing parameters you can save them many times as well. The file with the best settings will be used as the basis of the expert advisor's work.
Additional optimization of an expert advisor.
It is recommended to perform additional optimization before you use an expert advisor on real accounts.
Optimization of a forward period on an expert advisor is not additional optimization! It's imperative that you avoid this error!
All optimization of an expert advisor should be excluded from a forward test.
The main principles of additional optimization are worth explaining. As long as any small changes to the parameters do not destabilize a system it is accepted that the system is stable.
'Small changes in parameters' is the important phrase here. Here is how this principle should be realized when additionally optimizing expert advisors:
You should change the expert advisor parameters by a small degree and launch optimization on a forward period.
You can choose the best settings and save them once additional optimization on a forward period has taken place and the output parameters such as number of traders, max and min drawdown and profitability match those received at testing on a forward period.
The accuracy of the expert advisor's optimization should be checked and you can achieve a better group of settings.
It is impossible to say exactly which parameters should be additionally optimized as different parameters need to be additionally optimized according to the expert advisor.
You should be very careful when making all of these adjustments: take small steps and alter the parameter values using narrow limits.
An expert advisor should be tested on a forward period after additional optimization.
If the results are better than after optimization on a test period, you should finally save settings to a .set file which can be then used for trading with an expert advisor
BUT on a demo account (at first).
You should be able to make some profit on a real account once an expert advisor shows good results on a demo account.
We can draw the following conclusion from what has been discussed here.
Only qualitative optimization of an expert advisor and its testing on historical and forward periods can ensure a high probability (even if it is not 100%) of its stable work on a real account.
Is this hard? Yes, it is!
But you will be able to make profit completely automatically.
And you will have been rewarded for your persistent and patient study of the expert advisor optimization principles using the Meta Trader4 platform.