Optimising an Expert Advisor with MetaTrader 4

A key feature provided by MetaTrader 4 is that it allows you to optimise the parameters of an EA. The optimiser will find the most profitable settings for a given time period. This tutorial will teach you how to optimise an EA on MT4.

Configuring the forex strategy optimiser

In the strategy tester (menu: View + Strategy Tester), click on "Expert properties", then click on the "Testing" tab. The first part of this window relates to the backtest, the deposit, the account's currency and a trade direction restriction (this option is useless).

MT4 test

The second part relates to the optimiser. The optimisable parameters are:

  • The account balance
  • The profit factor (gross profit / gross loss)
  • Expected payoff, the mathematical expection of victory (average profit / loss factor)
  • Maximum drawdown expressed as a percentage or amount of money

The last line refers to the genetic algorithm that attempts to make the process more intelligent. When the software sees that some parameters will inevitably result in a loss, the algorithm ignores the test. This option speeds up the optimisation which can sometimes be very long.

The Input parameters tab

Optimisation

This window displays all of the parameters of the EA that can be modified.

Check the box of the parameters that are to be optimised. When you change the numbers, you can test different configurations according to a range of values.

The "initial value" represents the minimum value of the parameter to be tested, the "stop" the maximum value and the "step" the increment of variation when going from the minimum to the maximum value.

The default "value" will be used for parameters that are not checked.

In this example we are testing the maximum number of long or short positions. The optimiser will test all the possibilities going from 10 positions, 11, 12... up to 15.

The Optimisation tab

Optimisation

The "Optimisation" tab allows one to define the parameters that will not be taken into account in the results. For example, it is possible to eliminate the results if the maximum drawdown is 70%.

After choosing your parameters in the three tabs, click on "OK".

Launch the MT4 strategy optimiser

In the strategy tester's window, check the "optimisation" box and click on the "initial value" button to launch the optimisation process.

Optimisation

The optimisation results

The results appear in the "Optimisation of results" tab.

MT4 optimisation

The list only displays the positive results, they can be sorted by clicking on the column titles and saved with a right-click on the table.

You can now select the efficient parameters and insert them into a new backtest. You just need to change the settings in "Expert properties", parameters tab, "value" column and once again launch the expert advisor backtest.