How to Backtest a Metatrader EA the Right Way, Part III - Expert Advisor Optimization
Once we learned how to run the backtes of expert advisor and improve the accuracy of a backtest, it’s time to optimize it. Optimization is a process of selecting the EA’s parameters when it gives the best results on the backtest.
Most experts have external parameters that you can change. By changing the parameters you changing the profitability of the EA and the way it works.
If you have access to the source code of your EA you can specify the external parameters, for example
extern int SellStop = 50; extern int TakeProfit = 20;
After that you can run the tester with different parameters of SellStop and Take profit. After you run the EA with different parameters you will be able to chose the optimal set of parameters.
Fore tester optimization you need to check “Optimization” option and by pressing the Expert Properties select the parameters you want to optimize. Then chose the Start value of the parameter, Stop value, and the size of the Step in which tester will switch that parameter for different runs. It looks like this:

Once you put the check mark into and hit “Start” then tabs “Optimization Results” and “Optimization Graph” will appear. Click on “Optimization Results” tab and right click on the field of the tab. You will see the following window:

You can put the check mark next to Skip Useless Results that option will skip the negative runs of the tester. Now the Strategy Tester will run the EA through the history and with different optimization settings you chose in Expert Properties -> Input tab. The number of each run and the total number will be shown at the left bottom corner.
Sometimes the optimization runs can take quite a long time depending on the number of parameters are being optimized and number of steps for each parameter.

After each run the ending balance of that run is reflected in the Optimization Graph as well as in Optimization Results where you can see all the optimization parameters with ending profit and other factors. Here is an example of an optimization graph.

By clicking at point of interest on this graph Strategy Tester will return you to the Optimization Results tab with the optimization parameter at which the tester achieved that ending balance.

Double click at the results line and Strategy Tester. You can select whatever parameters you want. You may base your selection on highest profit, or highest profit factor, or the lowest drawdown. Double clicking will set the selected parameters into the Expert properties. Uncheck the Optimization option and run the Strategy Tester with the selected parameters. That will return the results of the Expert Advisor back test - the results it would have on the historical data with the selected parameters.

That’s how “Holy Grails” are made in those online Forex Trading Robots sales letters. Now you can honestly make yourself such a “Holy Grail” on backtests
Now if you are satisfied with the particular back-test run, save the settings of this run into *.set file by going Expert Properties -> Inputs -> Save and save it into Experts/presets folder.

After that you can apply saved settings to Expert Advisor that attached to your trading chart. To do that right click on your chart with that has an EA attached to it. Select Expert Advisors -> Properties -> Inputs -> Load. Select the saved .set file and hit Open then hit OK that will load your optimized parameters into the EA to do the live trading.
That’s all you need to run your EA with the optimized parameters on the back-test. Hopefully the live trading results of this EA will be similar to those on the back-test.













