Backtester overrides timeframesettings of variables?

 

Hi,


maybe it is basic knowledge but why is it that the MetaTrader backtester overrides the timeframesettings I assigned to my variables?

For example: I want the EA to buy after an engulfing candle pattern has formed on a 5 min chart, so I declare the variables for iClose and iOpen and set them to PERIOD_M5. Logic dictates that this should mean that the backtester only places orders according to candles on the M5 timeframe as written in the code regardless of the timeframeoption chosen in the backtestwindow. As it is, the EA produces different results for the 5 min and 15 min testing periods. The results reveal completely different trades even though it should consider M5 candles only. Any explanation would be great.

If there is any reference regarding this phenomenon be it on this forum or any other or in Google or whatever, I'm sorry I couldn't find any. Thanks in advance.

 
Show example code that produces this...
 
Apart from code, it would also depend on what you have selected for the Tester Model and Period, and the data you have available.
 

Below is the attached code.

Files:
 

You can NOT get bar zero data for other timeframes/pairs in the tester.

Other problems

 

I see... So no matter what time period I assign to my variable in the code, if I choose a different period in the tester the tester will take that period instead... Thanks a lot.

1) Only in the tester or in live trading as well?

2) Does this limitation apply only to bars or to indicators as well? i.e. Can I get zero data from a 15 min MACD when I'm on a 5 min chart?

3) There is no problem when trying to access non zero data right?

 

I didn't say that. The chart period is what you chose in the tester. Data comes from what you coded.

  1. What part of "in the tester" was unclear?
  2. Where do you think the indicators get their data?
  3. non-zero bar data, correct.
 

Okay. Thx.

Some more things.

a)

if (EachTickMode && Bars != BarCount)

"Bars is unreliable, once you reach max bars on chart Bars doesn't change. Volume is unreliable. Always use Time."

if (EachTickMode && Time != BarCount) 

Like this? Produces the followig msg when compiling: '!=' - series array has no left square bracket. zero shift assumed E:\MetaTrader\experts\TrainingEA[1_1].mq4 (67, 29)

b)

Total = OrdersTotal();
   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
This makes the EA incompatable with any other EA including itself on other charts. Also you MUST count down when closing orders. Always test return codes.
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol() ){              // and my pair.

I replaced Total = OrdersTotal(); with pos = OrdersTotal(); as well as the for cycle from above with the one you suggested. Produces the msg pos - variable not defined. when compiling.

 
  1. Time != BarCount
    Time vs int makes no sense.
    datetime Time0;
    ...
    if (Time[0] != Time0){ Time0=Time[0]; ...
    

  2. Produces the msg pos - variable not defined. when compiling.
    When in doubt THINK
    for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (

Reason: