MQL5 Free EA – Verification by backtesting 24 "Moving Average Crossover"

MQL5 Free EA

In the “Verification by backtesting" series, we verify the performance of free EAs registered in the MQL5 community from the backtesting results. We hope it will help you choose EA.

* Membership registration (free) is required to download EAs and indicators from the MQL5 community, so let’s create an account by referring to this article!

The 24th edition is Moving Average Crossover“.

About Moving Average Crossover

This EA seems to be an experimental test EA, and good results cannot be expected unless the minimization is successful. Therefore, I would like to take this opportunity to introduce one of the optimization methods “Forward optimization".

Quoting from MQL5 official page

This robot works with crossing of moving averages. Moving averages are used mainly to follow trends, the strategy of crossing moving averages has the main purpose of taking advantage of large bullish and bearish movements.

All parameters are editable and easy to use, this is an experimental project.

Trading “Moving Average Crossover"

The logic of this EA is simple: enter with two moving averages (short-term and long-term) crosses and exit with the set Take Profit/Stop Loss (TP/SL) values.

  • Golden cross (buy signal): when the short-term moving average crosses from the bottom to the top (crosses) the long-term moving average.
  • Dead cross (sell signal): when the short-term moving average breaks through from top to bottom (crosses) the long-term moving average.

However, since there does not seem to be a function to close trades on the opposite signal (cross), we need to optimize TP/SL as well.

Optimization methods (Forward optimization)   

In order to implement the optimization method introduced this time, it is necessary to understand the characteristics of the EA to some extent. Also, please note that there are some prerequisites.

  1. There are multiple modifiable parameters, and changing the numeric value essentially does not change the logic.
  2. When optimizing, we want to perform backtesting with “open price only", so it is desirable that the EA does not have a function such as trailing.
    There is nothing that cannot be done even with “All Ticks", but it is realistically difficult because it takes time to test.
  3. In the same sense, it is desirable that the backtest of the EA itself is fast.

Starting the Strategy Tester

First, launch the strategy tester from the MT5 menu and select “Forward optimization".

Configuring the Strategy Tester

  1. Currency Pair: EURUSD #
  2. Timeframe: H1 * This time, based on the results of preliminary tests, EURUSD and H1
  3. Period: 2013.01.01 – 2022.12. 31
  4. Forward period setting: 1/2 (can be changed as needed)
    * Since the test period is set to 2013.01.01 – 2022.12.31, the optimization period is 1/2 of the first half (2013.01.01 – 2017.12.31) and the second half 1/2 (2018.01.01 – 2022.12.31) is the forward period (test based on optimization results).
  5. Historical data to use: Open prices only
  6. Optimization method: Genetic algorithm
  7. Optimization ranking: Profit Factor order
    * In this case, we used Profit Factor max, but other indicators may be better. 

Setting Parameters

  • The EA parameters are as follows:
  • lot: Lot
  • TakeProfit: Take Profit
  • stoploss: Stop Loss
  • SlowAverage_MediaLenta: Period of the long-term moving average
  • FastAverage_MediaRapida: Short-term moving average period MetodoMM_Slow_Lenta: Types of long-term moving averages
  • MetodoMM_Fast_Rapida: Types of short-term moving averages
  • This time, we will optimize four of these items: take profit, stop loss, and periods of long-term and short-term moving averages.

Enter a number in Start-Step-Stop for the parameter to be optimized. I think that the range of input values is better with values that do not deviate too much considering how to trade.

In the take profit example in the table above, it means backtesting by changing the parameters one by one (5, 6, 7, 8,…, 249, 250) from 5~250.

There are 246 take profit combinations, 97 stop losses, and 226 and 71 long-term and short-term moving average periods, for a total of 246 x 97 x 226 x 71 = 382,889,562.

However, instead of running all of the approximately 400 million backtests, we use a genetic algorithm to aggregate them into conditions with good performance and limit the number of times.

Perform backtesting

When you press the “Start" button in the lower right corner, the optimization period is first backtested. After that, the forward period test starts automatically.

  • Optimization period: 2013.01.01 – 2017.12.31

Since we are screening with Profit Factor max, plots with darker green color indicate higher profit factors and better performance.

  • Forward Period: 2018.01.01 – 2022.12.31

The forward period test is tested using the parameters optimized in the backtest described above.

Backtest (optimization) and forward test results 

  • If you have a good intuition, you may have noticed it just by looking at the figure above.

This is the result of sorting the profit factor of the backtest (blue frame) in descending order. The numbers in the red frame on the left are the results when forward (virtual) is performed with the same parameter settings as the backtest.

Even if you perform well in the backtest (optimization period), you can see that it is completely negative in the subsequent forward test.

Backtesting with optimized parameters

The profit and loss curve is as follows:

Optimization period: 2013.01.01 – 2017.12.31
Forward Period: 2018.01.01 – 2022.12.31
  • It’s hard to believe that the graph was tested with the same parameters, but this is the reality.

Optimization period and forward period, what are the conditions for both sides?

The results are not very good, but they are in the optimization results.

If the operation had started on 2018.01.01, I don’t think the above parameters could have been selected, but if it had been selected, it could be said that it was positive after that. However, we cannot guarantee that the same results will occur in the future. It is important to determine the optimization results.

As for Forward optimization, it’s a good idea to master it as one of the techniques!


Up-and-coming MT5 FX broker [NOZAX] → → → Click here for details!

Posted by GOMA