How to backtest multiple moving average combinations

Greetings,

I wonder if it is possible to write a script which will backtest an EA multiple times, but each time using a different set of moving averages in order to determine the most profitable combination?

An example would be to have 2 MAs, a short one and a long one.

The short one could be 3, 5, 8, 10, 14.

The long one could be 26, 30, 35, 40.

The script would change the value of the EA’s moving averages after each test and print out the results.

I do possess the programming skills to write such a script, but I wonder whether it is possible with current API and libraries.

Thank you!

Just put the short and long ma’s as input parameters and use mt5 optimizations of inputs in the strategy tester.

Of course it possible:

enum  ShortPeriod { SP_3=3,   SP_5=5,   SP_8=8,   SP_10=10, SP_14=14 }
enum   LongPeriod { LP_26=26, LP_30=30, LP_35=25, LP_40=40 }
input ShortPeriod fast=SP_3;
input  LongPeriod slow=LP_26;

You can only do this for a range of int s, e.g. slow = 25 to 40 step 5. The OP has specific values that is not constant multiples.

Thats right but he can use step 1 from 3 to 14 and take the best or throw whats not needed.

Or he can divide the slow into number of sets

Fitst set for slow staeting 3 ending 5 step 2

Test against all sets of long ma

And go on to next set of short ma.

A little work but easy

You can do this in oninit() function.

Run the moving average cross over all candles and simply count the crossovers.

Change a parameter and run it again, as many times as desired and then compare results.

Ultra fast when compared to the super slow backtester.

You don’t need these timely backtests and if you run it in the oninit() it will be adaptive and always up to date.