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.
 
Jianan Wang: I wonder if it is possible

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

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

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;

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

You can only do this for a range of ints, e.g. slow = 25 to 40 step 5. The OP has specific values that is not constant multiples.
 
whroeder1:
Of course it possible:

You can only do this for a range of ints, 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.

Reason: