Download MetaTrader 5

MT4 Multi-timeframe EA backtesting on strategy tester

To add comments, please log in or register
Find out how to add a video in the messages editor
Kaloko
619
Kaloko 2015.01.14 18:12 

Hello guys,

A programmer created a multitimeframe EΑ for me but as i can see i can't backtest it on strategy tester..

Could you please tell me if i can backtest mutitimeframe EA's on strategy tester and how i can do it..

I have searched all the web but i could not find anything related to that... 

It would be really helpfull if someone could give me some information

Alain Verleyen
Moderator
30743
Alain Verleyen 2015.01.14 21:28  
Kaloko:

Hello guys,

A programmer created a multitimeframe EΑ for me but as i can see i can't backtest it on strategy tester..

Could you please tell me if i can backtest mutitimeframe EA's on strategy tester and how i can do it..

I have searched all the web but i could not find anything related to that... 

It would be really helpfull if someone could give me some information

You can backtest MTF EA with MT4, you only need to have the data. What's your problem, what doesn't work ?

Tim144
501
Tim144 2015.06.14 23:41  
Alain Verleyen:
You can backtest MTF EA with MT4, you only need to have the data. What's your problem, what doesn't work ?

Hi Alain. Can you make MTF backtest in visual mode and also in optimizer ?

Gr. Tim 

Alain Verleyen
Moderator
30743
Alain Verleyen 2015.06.15 20:27  
Tim144:

Hi Alain. Can you make MTF backtest in visual mode and also in optimizer ?

Gr. Tim 

My answer was a mistake, I confused MT4 and MT5.

You cannot backtest or optimize MTF EA with MT4, only with MT5.

Tim144
501
Tim144 2015.06.16 09:34  
Alain Verleyen:

My answer was a mistake, I confused MT4 and MT5.

You cannot backtest or optimize MTF EA with MT4, only with MT5.

Too bad. Thank you for your honest answer.

But..........that means that I "only" have to have my indicators and EA converted to MT5.

I can backtest in MT5, and then run on MT4. The price data is still the same. Or...... not ? 

Alain Verleyen
Moderator
30743
Alain Verleyen 2015.06.16 14:20  
Tim144:

Too bad. Thank you for your honest answer.

But..........that means that I "only" have to have my indicators and EA converted to MT5.

I can backtest in MT5, and then run on MT4. The price data is still the same. Or...... not ? 

There price data will not be exactly the same, unless you found a broker which provide both platform with the same data.

Tim144
501
Tim144 2015.06.16 21:13  
Alain Verleyen:

There price data will not be exactly the same, unless you found a broker which provide both platform with the same data.

Ah. Ok. Really.

Thanks Alain 

JD4
1101
JD4 2015.06.22 17:50  
I seem to remember seeing people posting historical data loggers or testers on the Marketplace.   Not sure if someone has something there that can help you out with this problem or not.
forexmmm
190
forexmmm 2015.08.14 17:50  

I have a similar problem. I contacted meta quotes themselves and they flat out said mt4 cannot access multiple time frames in the strategy tester for multi time frame signal EAs.

So this brings us to the next question. Is there a work around for this? OR is the only option converting files to mt5 compatibility.

Tim144
501
Tim144 2015.10.18 15:06  
forexmmm:

I have a similar problem. I contacted meta quotes themselves and they flat out said mt4 cannot access multiple time frames in the strategy tester for multi time frame signal EAs.

So this brings us to the next question. Is there a work around for this? OR is the only option converting files to mt5 compatibility.

Hi Forexmmm, sorry for the late reply. Only saw it just now.

I haven't found any workaround yet. Have you? 

Dr Matthias Hammelsbeck
537
Dr Matthias Hammelsbeck 2015.10.29 22:01  
Tim144:

Hi Forexmmm, sorry for the late reply. Only saw it just now.

I haven't found any workaround yet. Have you? 

Hi Tim144,

just in this autumn 2015 I'm experimenting with some self written EAs. In this stage I can say:  

In my MT4 installation I can backtest MTF EAs.
And I’m able to visualize the testing progress in several charts with different timeframes used in the EA; though not simultaneously but in a consecutive manner. Please let me explain.
 
I prepared the historical tick data as described in Birt’s Tick Data Suite    (http://eareview.net/tick-data-suite).
Finally I got the fxt-Files for all relevant timeframes here and set them to read-only:

 

 

  

Here is the MTF EA (a very simple example only for this explanation). Please note: all timeframes are indicated explicitly, I never use “0”, “Period()”  or “PERIOD_CURRENT” for the timeframe parameter in the indicator functions or elsewhere!

 

#property strict
int g_fp;
int g_nTicks;
int OnInit() {
   g_fp = FileOpen ("Testfile_"+IntegerToString(Period())+".txt", FILE_TXT|FILE_WRITE);
   g_nTicks=0;
   return INIT_SUCCEEDED;
}
void OnDeinit(const int reason) {
   FileWrite (g_fp, "Number of Ticks = ", g_nTicks);
   FileClose (g_fp);  
}
void OnTick() {
   g_nTicks++;
   int tic;
   // EXPLICIT indication of the timeframes:
   double ma1 = iMA (Symbol(),PERIOD_M15,20,0,MODE_SMA,PRICE_CLOSE,0);
   double ma2 = iMA (Symbol(),PERIOD_H1,20,0,MODE_SMA,PRICE_CLOSE,0);
   double ma3 = iMA (Symbol(),PERIOD_H4,20,0,MODE_EMA,PRICE_CLOSE,0);
   if ((Bid > ma1) && (ma1 > ma2) && (ma2 > ma3)) {
      if (Buy()) {
         tic=OrderSend (Symbol(),OP_BUY,0.01,Ask,3,0.0,0.0,NULL,1234,0,Blue);
         FileWrite (g_fp, "Buy  Signal ", tic,
            " at ", TimeCurrent(),
            ": Bid = ", NormalizeDouble(Bid,Digits()),
            " ma1 = ", NormalizeDouble(ma1,Digits()),
            " ma2 = ", NormalizeDouble(ma2,Digits()),
            " ma3 = ", NormalizeDouble(ma3,Digits())); 
      }
      return;
   }
   if ((Bid < ma1) && (ma1 < ma2) && (ma2 < ma3)) {
      if (Sell()) {
         tic=OrderSend (Symbol(),OP_SELL,0.01,Bid,3,0.0,0.0,NULL,4321,0,Red);
         FileWrite (g_fp, "Sell Signal ", tic,
            " at ", TimeCurrent(),
            ": Bid = ", NormalizeDouble(Bid,Digits()),
            " ma1 = ", NormalizeDouble(ma1,Digits()),
            " ma2 = ", NormalizeDouble(ma2,Digits()),
            " ma3 = ", NormalizeDouble(ma3,Digits())); 
      }
   }
}
bool Buy () {
   int total = OrdersTotal();
   if (total == 0) return true;
   if (OrderSelect(0,SELECT_BY_POS) == true) {
      if (OrderType() == OP_BUY) return false;
      OrderClose (OrderTicket(),OrderLots(),Bid,3,Red);
      return true;
   }
   return false;
}
bool Sell () {
   int total = OrdersTotal();
   if (total == 0) return true;
   if (OrderSelect(0,SELECT_BY_POS) == true) {
      if (OrderType() == OP_SELL) return false;
      OrderClose (OrderTicket(),OrderLots(),Ask,3,Blue);
      return true;
   }
   return false;
}


For backtesting all my EAs and performing statistical analysis but without visualizing the progress in a chart I always let run the test with timeframe M1 and with the model “Every tick”.
 

For visualizing the behaviour of the EA I set “Visual Mode” and select the timeframe whose chart I want to see and run the test again. I do this step by step for all timeframes whose charts I want to see. Unfortunately it is not possible to see all charts simultaneously (I’ve found a bumpy workaround for this, see https://www.youtube.com/watch?v=ztxuzcVhJGk and https://gist.github.com/micclly/9451216).

A second problem I have: the indicators appear on the charts after the test, not during the test. Why???? Any ideas??? 

The important point is: the results (trades, statistic, my programmed output files) are the same regardless of the timeframe I use in the strategy tester.

For example, the content of the file created in the MTF EA shown above is totally equal for all timeframes:

Buy  Signal 1 at 2005.05.06 10:30:21: Bid = 1.29598 ma1 = 1.29464 ma2 = 1.29458 ma3 = 1.29437

Sell Signal 2 at 2005.05.06 14:00:04: Bid = 1.28471 ma1 = 1.29181 ma2 = 1.29324 ma3 = 1.29335

Buy  Signal 3 at 2005.05.11 02:00:00: Bid = 1.28852 ma1 = 1.2879 ma2 = 1.28675 ma3 = 1.28673

Sell Signal 4 at 2005.05.11 15:00:01: Bid = 1.28155 ma1 = 1.28391 ma2 = 1.28637 ma3 = 1.28639

Buy  Signal 5 at 2005.05.19 01:00:03: Bid = 1.26805 ma1 = 1.26757 ma2 = 1.26511 ma3 = 1.26498

Sell Signal 6 at 2005.05.19 22:00:00: Bid = 1.26339 ma1 = 1.26358 ma2 = 1.26443 ma3 = 1.26446

Buy  Signal 7 at 2005.05.26 03:33:49: Bid = 1.25997 ma1 = 1.2599 ma2 = 1.25913 ma3 = 1.25895

Sell Signal 8 at 2005.05.26 11:00:04: Bid = 1.254 ma1 = 1.25509 ma2 = 1.25801 ma3 = 1.2581

Number of Ticks = 724661


 
In summary: multi-timeframe EAS can be tested in the MT4 strategy tester as far as I can see.
Additionally the testing progress can be visualized on different charts in a consecutive manner.
 
 
Question:
Why Metaquotes does not implement the features of the MT5 tester into MT4??? Would be great. Then I (and other people too I guess)  would have a lot less problems :-)
Converting the EA-code from MQL4 to MQL5 is no option for me because I’m running several strategies on one currency pair and I need the hedging functionality.
 

I hope that will help a little bit

 

Matthias

 

12
To add comments, please log in or register