An important step in designing an automatic trading system is the optimization the parameters (inputs). Metatrader has an optimization feature that allows us to find the input values that enable us to make our Expert Advisor better on historical data (Backtesting).

How can I optimize?
The first step is to open the strategy tester from the top menu (click on view).
The tester opens. We choose the strategy name, the market to be tested and the time frame (Figure 1) in the various drop-down menus.
As a second step, click on “Expert Properties”.
Fig. 1
A window opens with all the inputs that have been encoded by our Expert Advisor programmer. In the example in Figure 2, we decide to optimize the first two parameters (a moving average and a penetration coefficient above average).
The Value column has the Default parameter. In the Start column, we set the startup value of the optimization. In Stops the last value we will test. In Step we enter the minimum increment value.
In the concrete case, the moving average will be optimized by a length of 20 to 200 passing through the value of 30, 40, 50 (that is 10 in 10 as an increment).

Fig. 2
Confirm the ok key and then tick the “optimization” box as in fig. 3. Click on “Startup”.

Fig. 3
Metatrader performs optimization of the parameters and returns the results and the optimization graph (Fig. 4).

Fig. 4
At this point, we can sort the results based on increasing (or decreasing) values of column headings, for example based on Net Profit.
Finally by right clicking on the test that we prefer, we can save the best default parameters and use them for our Expert Advisor instead of the default ones.

Fig. 5