Top Banner
How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester How do you correctly optimize expert advisors using the MetaTrader 4 strategy tester? Why do you need optimization at all and which expert advisor parameters should be optimized to achieve profitable currency trading on Forex? You will find all these answers in this article. MetaTrader 4 Strategy Tester has two important functions: the testing and optimization of expert advisors. Optimization is the process of selecting the optimal parameters for expert advisors. As a rule, a trader optimizes (improves) the input parameters of robots to make them as profitable as possible for minimum risk. The expert advisor optimization process is one of multiple testing using different input parameters in automatic mode by MetaTrader 4. That said simple optimization is nothing more than adjusting the expert advisor parameters to reflect history, i.e. to previous market conditions and price movements. If you optimized an expert advisor on historical data and set it to trade, pleased that the optimization results had been great, you wouldn’t receive the same results during real-time trade. The reason is you only performed an ADJUSTMENT of parameters, but not real optimization. Correct and qualitative expert advisor optimization, or forward testing, includes both stages. The first stage is optimization (or, to be more precise, adjustment) of an expert advisor on a certain segment of history, which is called a test (historical) period. The results of the adjustment are presented in a table in the form of expert advisor input parameters. Using the best parameters, a robot is set to “trade” on a new time segment where it hasn’t been adjusted and doesn’t know how to behave. This segment 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. Here are the recommended historical and forward periods for expert advisors working on the following timeframes: H1 – the recommended historical period is 2 years, forward period – 6 months; M30 – 1.5 years and 4 months; M15 – 1 year and 3 months. It is not recommended to test expert advisors on smaller timeframes. In order to better understand historical and forward periods, look at the picture below: For example, we can assume today’s date as November 30th 2011 and we have decided to optimize an expert advisor on the period M15 with a historical period of 1 year and the forward period of 3 months. We would therefore have the end of the historical period coming in at August 30th 2011 and the
10

How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

Oct 24, 2014

Download

Documents

eri8vz4rke

When optimizing expert advisors, what is the bets way to use Meta Trader 4 strategy tester?

Which expert advisor parameters should be optimized when looking to profitably trade forex currencies and why is optimization needed at all?

This article will answer these questions.

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

How to Optimize an Expert Advisor Using MetaTrader 4

Strategy Tester

How do you correctly optimize expert advisors using the MetaTrader 4 strategy tester?

Why do you need optimization at all and which expert advisor parameters should be optimized to

achieve profitable currency trading on Forex? You will find all these answers in this article.

MetaTrader 4 Strategy Tester has two important functions: the testing and optimization of expert

advisors. Optimization is the process of selecting the optimal parameters for expert advisors. As a rule,

a trader optimizes (improves) the input parameters of robots to make them as profitable as possible for

minimum risk. The expert advisor optimization process is one of multiple testing using different input

parameters in automatic mode by MetaTrader 4. That said simple optimization is nothing more than

adjusting the expert advisor parameters to reflect history, i.e. to previous market conditions and price

movements. If you optimized an expert advisor on historical data and set it to trade, pleased that the

optimization results had been great, you wouldn’t receive the same results during real-time trade. The

reason is you only performed an ADJUSTMENT of parameters, but not real optimization.

Correct and qualitative expert advisor optimization, or forward testing, includes both stages. The first

stage is optimization (or, to be more precise, adjustment) of an expert advisor on a certain segment of

history, which is called a test (historical) period. The results of the adjustment are presented in a table

in the form of expert advisor input parameters. Using the best parameters, a robot is set to “trade” on a

new time segment where it hasn’t been adjusted and doesn’t know how to behave. This segment 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. Here are the

recommended historical and forward periods for expert advisors working on the following timeframes:

H1 – the recommended historical period is 2 years, forward period – 6 months;

M30 – 1.5 years and 4 months;

M15 – 1 year and 3 months.

It is not recommended to test expert advisors on smaller timeframes. In order to better understand

historical and forward periods, look at the picture below:

For example, we can assume today’s date as November 30th 2011 and we have decided to optimize an

expert advisor on the period M15 with a historical period of 1 year and the forward period of 3 months.

We would therefore have the end of the historical period coming in at August 30th 2011 and the

Page 2: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

beginning of this period at August 30th 2010. Let’s now look at the process of testing and optimization

of expert advisors in detail.

Forex Optimization - Step 1

Let’s adjust the Strategy Tester. Open the Strategy Tester in the menu of the trading terminal. Go to the

“View” section and choose the expert advisor which you are going to optimize from the tab “Expert

Advisor”. Choose your currency pair from the drop-down list box “Symbol”. “Model” – open prices

only. Then choose the period for which you have the optimization settings by ticking the checkbox “Use

date” and select the time period for testing the advisor.

Now you need to download a currency rates archive. MetaTrader 4 users have access to rates with a 1

minute minimum. You should adjust the data download settings before downloading the rates. To do

this, go to “Tools” -> “Options” then open the tab “Charts” and set the maximum values in the fields

“Max bars in history” and “Max bars in chart”.

Page 3: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

Then download the rates by going to “Tools” -> “History Center” -> “Symbols – Currency pair – Period”,

and choose a currency pair and time period.

It should be noted that rates offered by dealing centers will not give you a modeling quality above 90%

(90% is an ideal variant). This is because you download data from MetaQuotes servers, which often offer

incomplete archives with missing rates for definite time periods (up to several months).

Look at the picture below for an example of a missing period between 10.06.2011 and 22.09.2011. 3

months are missing!

Page 4: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

Do you think a trader could perform qualitative optimizations of an expert advisor if he had nothing to

work with? Of course not, so the results of modeling in these conditions are hardly 40% let alone 90%.

However, there is a solution of this problem. You can download full archives of tick rates from the

DukasCopy dealing center website , which allow gives a modeling quality result of up to 99%.

Forex Optimization - Step 2

Now you need to load an optimization file to the strategy tester, if 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 either in the folder С://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).

Page 5: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

The expert advisor will have initial parameters loaded which you should change on the “Inputs” tab. To

change them, tick off items in the “Variable” column which should be changed in 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. Doing this will help avoid confusion and you

will always know which expert advisor belongs to which optimization file. You also should include the

name of a currency pair and timeframe in the name of an 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”. (Genetic

algorithm is a “clever” function that examines parameters and discards knowingly unprofitable ones

meaning that the number of variants that are examined and required time decreases).

To finish press “OK”.

Page 6: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

Optimization - Step 3

Launching an expert advisor optimization. Tick the checkbox “Optimization” right before launching an

optimization of expert advisor parameters. Once you have done this you can press “Start”.

The testing process for a Forex expert advisor on a test period may be anything from several minutes to

several hours or even days. Everything depends on the number of optimized parameters for each expert

advisor.

Optimization - Step 4

A graph is formed on the “Optimization Graph” tab at the end of optimization with the more profitable

expert advisors parameters being marked by a darker color. You should combine work with charts with

the analysis of the table “Optimization Results” where you can clearly see input parameters. There is no

point in checking all the parameters and searching the best ones, because many of them are almost

identical. You’d also waste too much time checking hundreds of combinations. It would be more

convenient, for example, to sort them by profitability and check the combinations with the best results.

Page 7: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

To do this, click the right mouse button on a line with a combination with maximum profit and select

“Set Input Parameters”.

A tester window will open where you 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. But this depends on the algorithm of your expert advisor. If it is based on open prices, testing

according to every tick will show incorrect results! That is why before optimizing an expert advisor, you

should understand its operation logic. Untick the checkbox “Optimization” and press “Start” for testing

the expert advisor with optimized input parameters on the test period.

Test analysis is done using the “Graph” and “Report” tabs. The more smooth and ascending the profit

chart is, the better the input parameters are.

Accordingly, if a chart is a broken line and shows descending movement instead of ascending movement

it means that input parameters are unsatisfactory so shouldn’t be used for your expert advisor.

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, you shouldn’t use this chart for making judgments about input parameters.

Page 8: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

Information which is more convenient for perception and analysis, is presented on the tab “Report” of

the MetaTrader 4 platform strategy tester. Having opened the tab, you will see the following:

Then we use various combinations of input parameters in turn, sorting them by different parameters.

When choosing combinations, you should pay special attention to parameters such as “Number of

trades” (different for each type of expert advisor) and “Maximal and minimal drawdown”. You should

test an expert advisor on a forward period when a “nice” ascending chart and successful results (good

profit, small drawdown, etc.) emerges with another set of parameters.

Optimization - Step 5

Testing an expert advisor on a forward period. Go to the “Settings” tab and set dates for the beginning

(From) and the end (To) of the forward period instead of the historical period time interval. The forward

period starts from the end of the historical period and ends under today's date. The “Start” button

launches testing of the robot with the given input parameters, received at the first stage of

optimization.

If the tester shows good results (analyzed on the basis of graph and report), you can save this

combination of parameters. To do this open the “Settings” tab and click 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.

Page 9: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

Good results may appear several times in the course of testing of an expert advisor with different

parameters, so, you can save them several times, too. The file with the best settings will be used as the

basis of the expert advisor’s work.

Optimization - Step 6

Additional optimization of an expert advisor. Before using an expert advisor on a real account, it is

recommended to perform additional optimization. Additional optimization is not optimization of an

expert advisor on a forward period! It’s vital that you don’t make this mistake! What you should do is to

completely exclude optimization of an expert advisor on a forward test! Let’s first explain the underlying

principle of additional optimization. It is known that a system is considered to be stable providing that

small changes of parameters don’t destabilize it. The key phrase in this definition is “small changes of

parameters”. 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. If the output parameters (maximal and minimal drawdown, profitability, number of

trades, etc.) do not differ from those received at testing on a forward period, after additional

optimization on a forward period, you can choose the best settings and save them. You will check the

accuracy of an expert advisor’s optimization and get a better group of settings. Different parameters

should be additionally optimized for different expert advisors, so we cannot tell you the exact

parameters that you should additionally optimize. All these adjustments should be done very carefully:

change values of parameters within fairly narrow limits and use small steps. An expert advisor should

Page 10: How to Optimize an Expert Advisor Using MetaTrader 4 Strategy Tester

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).

After an expert advisor shows good results on a demo account, you will be able to use it for profitable

trading on a real 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 difficult? Yes, it is!

But you will be able to make profit completely automatically. And your patience and persistent study of

the principles of expert advisors optimization in the MetaTrader 4 trading platform will have been

rewarded.

http://fxtester.com