Download MetaTrader 5

Meta Trader 4 Tester Bugs

To add comments, please log in or register
imanuel
31
imanuel  

I found some strange behaviour on MT4 when you are testing an EA or Indicator that calls another indicator that has higher time frame than your tester time frame. It worked well on trading environment, but doesn't works on tester environment. Given example you are testing the indicator using M1 period and the indicator call the M5 indicator to display the current M5 High and current M5 Low, then you will get the different indexing count.

int OnCalculate(const int rates_total, int prev_calculated, ....

      if (prev_calculated>0)

         for(int i=0; i<prev_calculated && !IsStopped(); i++)   // refreshed calculation

 { 

            ExtCurrM5H[i] = iHigh(Symbol(), PERIOD_M5, i);  // indexing on M1 period doesn't correlate to M5 period

        ExtCurrM5L[i] = iLow(Symbol(), PERIOD_M5, i);   // indexing on M1 period doesn't correlate to M5 period

 } 

      else

         for(int i=prev_calculated; i<rates_total && !IsStopped(); i++)   // initial calculation

            ExtCurrM5H[i] = iHigh(Symbol(), PERIOD_M5, i);  // this indexing is correlated

        ExtCurrM5L[i] = iLow(Symbol(), PERIOD_M5, i);   // this indexing is correlated

However it is working well on real environment. So actually there is discrepency of indexing between the tester environment and trading environment. That mean if your EA is using different time frame than tested time frame, then the testing resut is just crap.

Is there anyway get around this bug? 

graziani
2007
graziani  

well, there is an old bug in MT4 tester, when you are using multiple time frames and open prices method, the prices are not copied correctly in higher TFs,  actually probably all other TFs, i don't remember details. I guess this is causing you trouble.

switch to every tick method and it will be OK.

whroeder1
15589
whroeder1  
imanuel:

I found some strange behaviour

That mean if your EA is using different time frame than tested time frame, then the testing resut is just crap.

  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. ExtCurrM5H[i] = iHigh(Symbol(), PERIOD_M5, i);  // indexing on M1 period doesn't correlate to M5 period
    Of course it is. I is the index into your buffers for the current chart and you're asking for data from the M5 chart 5i minutes ago. Nothing strange, you're getting exactly what you asked for.
    Don't use it for any other timeframe. Don't mix apples and oranges.
    datetime when = Time[i];                            // Chart
    int      iM5 = iBarShift(NULL, 0, when);            // M5
    double   m5value = iHigh(Symbol(), PERIOD_M5, iM5); // M5
    ExtCurrM5H[i] = m5value;                            // Chart

imanuel
31
imanuel  

Hi WHRoeder,

Thanks for the reply, I tried to run this simple indicator that display previous M5 hi and lo value on M1 chart on a strategy tester session using M1 tester. However the M5 display is not updated along with M1 data in the buffer. It seems that the data in the buffer is only updated on M1 period, that will be a big problem if we write EA using multiple time frame indicators. I'm not sure whether MT5 also have the same problem.

MT4 Tester Buffer 

for(int i=0; i<rates_total && !IsStopped(); i++)
{
    PrevM5H[i] = iHigh(NULL, PERIOD_M5, 1+iBarShift(NULL,PERIOD_M5,Time[i],false));
    PrevM5L[i] = iLow(NULL, PERIOD_M5, 1+iBarShift(NULL,PERIOD_M5,Time[i],false));  
}
graziani
2007
graziani  

@imanuel 

you are doing something wrong. show the whole code.

 

the bug i was talking about is still present:

   scannedTime = iTime(NULLPERIOD_M1, 0);
   Print(TimeToString(scannedTime, TIME_SECONDS), " high: ", iHigh(NULL, PERIOD_M1, 0), " <> ",
         iHigh(NULL, PERIOD_M5, 0), " <> ", iHigh(NULL, PERIOD_M5, 1));

 

gives for every tick on M1

16:13:23 2014.07.18 18:00  Otvaralo V4.19 EURUSD,M1: 18:00:00 high: 1.35088 <> 1.35088 <> 1.35132
16:13:23 2014.07.18 18:01  Otvaralo V4.19 EURUSD,M1: 18:01:00 high: 1.35081 <> 1.35092 <> 1.35132
16:13:23 2014.07.18 18:02  Otvaralo V4.19 EURUSD,M1: 18:02:00 high: 1.35078 <> 1.35092 <> 1.35132
16:13:23 2014.07.18 18:03  Otvaralo V4.19 EURUSD,M1: 18:03:00 high: 1.35067 <> 1.35092 <> 1.35132
16:13:23 2014.07.18 18:04  Otvaralo V4.19 EURUSD,M1: 18:04:00 high: 1.35057 <> 1.35092 <> 1.35132
16:13:23 2014.07.18 18:05  Otvaralo V4.19 EURUSD,M1: 18:05:00 high: 1.35058 <> 1.35058 <> 1.35092
16:13:23 2014.07.18 18:06  Otvaralo V4.19 EURUSD,M1: 18:06:00 high: 1.3506 <> 1.3507 <> 1.35092
16:13:23 2014.07.18 18:07  Otvaralo V4.19 EURUSD,M1: 18:07:00 high: 1.35046 <> 1.35072 <> 1.35092
16:13:23 2014.07.18 18:08  Otvaralo V4.19 EURUSD,M1: 18:08:00 high: 1.35055 <> 1.35072 <> 1.35092
16:13:23 2014.07.18 18:09  Otvaralo V4.19 EURUSD,M1: 18:09:00 high: 1.35061 <> 1.35072 <> 1.35092
16:13:23 2014.07.18 18:10  Otvaralo V4.19 EURUSD,M1: 18:10:00 high: 1.35077 <> 1.35077 <> 1.35077

 and for open prices on M1

16:11:16 2014.07.18 18:00  Otvaralo V4.19 EURUSD,M1: 18:00:00 high: 1.35088 <> 1.35088 <> 1.35132
16:11:16 2014.07.18 18:01  Otvaralo V4.19 EURUSD,M1: 18:01:00 high: 1.35081 <> 1.35088 <> 1.35132
16:11:16 2014.07.18 18:02  Otvaralo V4.19 EURUSD,M1: 18:02:00 high: 1.35078 <> 1.35088 <> 1.35132
16:11:16 2014.07.18 18:03  Otvaralo V4.19 EURUSD,M1: 18:03:00 high: 1.35067 <> 1.35088 <> 1.35132
16:11:16 2014.07.18 18:04  Otvaralo V4.19 EURUSD,M1: 18:04:00 high: 1.35057 <> 1.35088 <> 1.35132
16:11:16 2014.07.18 18:05  Otvaralo V4.19 EURUSD,M1: 18:05:00 high: 1.35058 <> 1.35058 <> 1.35092
16:11:16 2014.07.18 18:06  Otvaralo V4.19 EURUSD,M1: 18:06:00 high: 1.3506 <> 1.3506 <> 1.35092
16:11:16 2014.07.18 18:07  Otvaralo V4.19 EURUSD,M1: 18:07:00 high: 1.35046 <> 1.3506 <> 1.35092
16:11:16 2014.07.18 18:08  Otvaralo V4.19 EURUSD,M1: 18:08:00 high: 1.35055 <> 1.3506 <> 1.35092
16:11:16 2014.07.18 18:09  Otvaralo V4.19 EURUSD,M1: 18:09:00 high: 1.35061 <> 1.35061 <> 1.35092
16:11:16 2014.07.18 18:10  Otvaralo V4.19 EURUSD,M1: 18:10:00 high: 1.35077 <> 1.35077 <> 1.35077

 

so the open prices REFRESHES the last bar of the higher TF, but it doesn't refresh it to correct value!

imanuel
31
imanuel  

Hi Graziani,

Good to know about the bug, thank you for the info. Please see attached is my indicator code. I don't understand why it shows different result if I run it on trading chart and testing chart. Let me know how to fix this. Thanks v much.

Files:
testind.mq4 3 kb
Ian Venner
2584
Ian Venner  
imanuel:

Hi Graziani,

Good to know about the bug, thank you for the info. Please see attached is my indicator code. I don't understand why it shows different result if I run it on trading chart and testing chart. Let me know how to fix this. Thanks v much.


In the image you posted your test dates show July 1st - July 16 yet you are pointing to a section of the chart at 26 June that is before the test period.
imanuel
31
imanuel  

Hi Graziani

I didn't select the test date range (it was not shown on the pic), so it will run trhough whatever the available date time data in my computer which happen to be 26 June. So does the tester chart and the trader charts so different result as what I get? I'm running on my latest MT4 Build 670, which supposed to support MTF EA testing. 

graziani
2007
graziani  

this indicator works like it is supposed to work when you put it on graph. 

however this is an indicator and i cannot do a backtest in strategy tester or guess what you are doing to get such results.

in MT4, beside the bug i showed you, everything works fine, so you can play with higher TF anyway you like.
i am doing it and i have no issues.

as there is no true debugger, you have to print the variables and see what is going on and where you made mistake.

for start
1) change the '1+ibarshift....' to 'ibarshift....',  ok maybe you have some agenda with it, but you are shifting unnecessary
2) check the starting point for refresh
3) verify that all buffers you are using are oriented in same direction (ArraySetAsSeries)

graziani
2007
graziani  

OK, i see it.

Will check later, i have no time now.

imanuel
31
imanuel  
graziani:

this indicator works like it is supposed to work when you put it on graph. 

however this is an indicator and i cannot do a backtest in strategy tester or guess what you are doing to get such results.

in MT4, beside the bug i showed you, everything works fine, so you can play with higher TF anyway you like.
i am doing it and i have no issues.

as there is no true debugger, you have to print the variables and see what is going on and where you made mistake.

for start
1) change the '1+ibarshift....' to 'ibarshift....',  ok maybe you have some agenda with it, but you are shifting unnecessary
2) check the starting point for refresh
3) verify that all buffers you are using are oriented in same direction (ArraySetAsSeries)


Still debugging now, however I suspect that iBarShift returns something different value especially when used in the strategy tester as compared in trading environment. No conclusive solution yet. I'll post it if I can solve the problem.
12
To add comments, please log in or register