iTime and iBarShift return wrong values when back test for multi timeframes - page 2

 

Hi jjc, thank you for your further explainations. Is there any way to report this bug to MetaTrader? It is really difficult to test an EA which invokes a multi-timeframe indicator...

 
jjc:

It depends on the indicators. An indicator which only uses the values passed in the buffers to OnCalculate() should be fine. An indicator which tries to get other data using the timeseries functions iBarShift, iTime, iClose etc will not work properly.

The problem is specifically with multi-timeframe indicators. 

(Much the same applies to offline charts. A multi-timeframe indicator on an offline chart sees the standard bar history, not the offline chart history.)

Thanks for your post, it has cleared something for me.

I have only just recently noticed this myself. While testing an EA in visual mode, the EA was taking trades that it apparently shouldn't as the MTF indicators weren't signalling trades. This was extremely puzzling as I couldn't find any fault in my code. Printing the iCustom values when conditions were found for a trade showed that the values did not relate to the indicator values in the data window at all.

Checking against a normal chart with the indicator showed that the iCustom calls were returning the correct values but the indicator in the visual mode chart was not displaying correctly.

 
gxforex:

Hi jjc, thank you for your further explainations. Is there any way to report this bug to MetaTrader? It is really difficult to test an EA which invokes a multi-timeframe indicator...

You can try writing to the Service Desk, but this isn't a bug as such. I don't think it's ever been intended to work the way you want it to work.
 
JC:

It depends on the indicators. An indicator which only uses the values passed in the buffers to OnCalculate() should be fine. An indicator which tries to get other data using the timeseries functions iBarShift, iTime, iClose etc will not work properly.

The problem is specifically with multi-timeframe indicators

(Much the same applies to offline charts. A multi-timeframe indicator on an offline chart sees the standard bar history, not the offline chart history.)

To be clear, it's on MTF indicator and it only happens when you place an indicator on a backtest chart, not when you are using iCustom (as reported by Keith). Of course, this discrepancy between iCustom() values and visual can be annoying if you are not aware of it.
 

Hi,

I think that problem exists whenever the data relied upon by the timeframe shifting routines is incorrect. For example here I was using iBarShift in an indicator on a normal chart.

As you can see all the shift values are incorrect. It appears that this may be more about how MT4 maintains, or doesn't maintain as the case may be, the bar history data that these indicators rely upon... At the time of doing this testing it was only the Monthly timeframe (i.e. 43200) that had the issues as all other timeframes worked properly.

When I tried the routine on another broker, and on live accounts and on a different demo account it worked properly, so it was just this account at this point in time.

And if it is bar history that is incorrect, it is possible that this might be a broker specific data maintenance issue, or possibly a user specific procedure that has been missed ?

So, is there something that I can do to ensure, or at least check, that the data that these routines relies upon is up to date?

Here is a Print of the erroneous data from the indicator:

2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 1 Time: 2017.07.16 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 2 Time: 2017.07.09 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 3 Time: 2017.07.02 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 4 Time: 2017.06.25 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 5 Time: 2017.06.18 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 6 Time: 2017.06.11 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 7 Time: 2017.06.04 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 8 Time: 2017.05.28 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 9 Time: 2017.05.21 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 10 Time: 2017.05.14 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 11 Time: 2017.05.07 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 12 Time: 2017.04.30 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 13 Time: 2017.04.23 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 14 Time: 2017.04.16 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 15 Time: 2017.04.09 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 16 Time: 2017.04.02 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 17 Time: 2017.03.26 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 18 Time: 2017.03.19 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 19 Time: 2017.03.12 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 20 Time: 2017.03.05 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 21 Time: 2017.02.26 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 22 Time: 2017.02.19 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 23 Time: 2017.02.12 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 24 Time: 2017.02.05 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 25 Time: 2017.01.29 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 26 Time: 2017.01.22 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 27 Time: 2017.01.15 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 28 Time: 2017.01.08 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 29 Time: 2017.01.01 00:00 timeframe: 43200 y: 0
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 30 Time: 2016.12.25 00:00 timeframe: 43200 y: 1
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 31 Time: 2016.12.18 00:00 timeframe: 43200 y: 1
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 32 Time: 2016.12.11 00:00 timeframe: 43200 y: 1
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 33 Time: 2016.12.04 00:00 timeframe: 43200 y: 1
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 34 Time: 2016.11.27 00:00 timeframe: 43200 y: 2
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 35 Time: 2016.11.20 00:00 timeframe: 43200 y: 2
2017.07.30 22:13:58.874 MTF_MA_V1.2 EURUSD,Weekly: y = iBarShift(NULL,timeFrame,Time[i]): i: 36 Time: 2016.11.13 00:00 timeframe: 43200 y: 2

Thanks