[Bug report] [mt4] time functions not working correctly in Strategy Tester.

 

Something's wrong with the strategy tester.

The following code draws fibo fans from the second and third period tops/bottoms, one going up and the other facing down.

(From 3rd period's - hour by default - top to 2nd bottom and from 3rd bottom to 2nd top)

It works just fine in realtime but won't "cooperate" in backtest. It will either draw one of the fibo fans the other way around - spreading into the past, or will be updating it's position every time there's new bar on the chart ( on the shown small timeframe. I remind that it should be 1) attaching to past hourly periods, 2) count the periods as real higher frame's bars not that, nomatter where we are, say, past 12 bars are last hour, and past 24 are previous hour. Nope, we might be in the first 10 minutes of new hour and only 2 past bars are our last hour).

Either way, my code's wrong or the backtester is flawed.

Can you please check this out?

//+------------------------------------------------------------------+

//| FiboFan.mq4 |

//| Jaroslaw Jaskulowski |

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "Jaroslaw Jaskulowski"

#property link "http://www.metaquotes.net"



#property indicator_chart_window

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+



extern int period = PERIOD_H1;

int init()

{

//---- indicators

//----

if(ObjectFind("FiboFanUp" + period) == -1)

ObjectCreate("FiboFanUp" + period, OBJ_FIBOFAN, 0, Time[0], Close[0]);



if(ObjectFind("FiboFanDown" + period) == -1)

ObjectCreate("FiboFanDown" + period, OBJ_FIBOFAN, 0, Time[0], Close[0]);



return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

ObjectDelete("FiboFanUp" + period);

ObjectDelete("FiboFanDown" + period);

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

//----

datetime time2 = iTime(Symbol(), period, 0) - 2* period / Period();

datetime time1 = iTime(Symbol(), period, 0) - period / Period();

int h1 = iHighest(Symbol(), Period(), PRICE_HIGH, period / Period(), iBarShift(Symbol(), Period(), time1));

int h2 = iHighest(Symbol(), Period(), PRICE_HIGH, period / Period(), iBarShift(Symbol(), Period(), time2));

int l1 = iLowest(Symbol(), Period(), PRICE_LOW, period / Period(), iBarShift(Symbol(), Period(), time1));

int l2 = iLowest(Symbol(), Period(), PRICE_LOW, period / Period(), iBarShift(Symbol(), Period(), time2));

ObjectSet("FiboFanUp" + period, OBJPROP_TIME1, iTime(Symbol(), Period(),l2));

ObjectSet("FiboFanUp" + period, OBJPROP_TIME2, iTime(Symbol(), Period(),h1));

ObjectSet("FiboFanUp" + period, OBJPROP_PRICE1, iLow(Symbol(), Period(),l2));

ObjectSet("FiboFanUp" + period, OBJPROP_PRICE2, iHigh(Symbol(), Period(),h1));

ObjectSet("FiboFanDown" + period, OBJPROP_TIME1, iTime(Symbol(), Period(),h2));

ObjectSet("FiboFanDown" + period, OBJPROP_TIME2, iTime(Symbol(), Period(),l1));

ObjectSet("FiboFanDown" + period, OBJPROP_PRICE1, iHigh(Symbol(), Period(),h2));

ObjectSet("FiboFanDown" + period, OBJPROP_PRICE2, iLow(Symbol(), Period(),l1));

//----

return(0);

}

//+------------------------------------------------------------------+
 
This is an Indicator not a Strategy (EA) . . . Indicators sometimes do strange things when applied to ST charts . . . learn what the ST is doing.
 
RaptorUK:
This is an Indicator not a Strategy (EA) . . . Indicators sometimes do strange things when applied to ST charts . . . learn what the ST is doing.


So you admit this is a bug.

What d oyou mean "learn what the ST is doing"? Learn where? Learn what?

The most important question is does it influence readings of the indicator done in the EA code or is it only gfx rendering bug?

 
doker:


So you admit this is a bug.

What d oyou mean "learn what the ST is doing"? Learn where? Learn what?

The most important question is does it influence readings of the indicator done in the EA code or is it only gfx rendering bug?

I don't think it is a bug, I think you are doing something that the ST was not intended for . . .

If you want to get as much functionality out of the ST as you can then you need to learn how it works by trial, error and observation. When an EA is run inside the ST it is exposed to the ST fabricated instrument . . . sometimes when you run an Indicator on top of the ST chart it sees the real instrument not the fabricated one . . . so if you are running the ST with EURUSD during 2009 sometime an Indicator (depending on how it is coded) will see EURUSD 2012 . . . this isn't an issue when you use iCustom from an EA running inside the ST.

This is based on my own observations and not something I have read . . .

 
doker:

Something's wrong with the strategy tester.

Either way, my code's wrong or the backtester is flawed.


datetime time2 = iTime(Symbol(), period, 0) - 2* period / Period();

datetime time1 = iTime(Symbol(), period, 0) - period / Period();

Your code wrong for the tester.

Indicators that do not use other time frames or pairs work fine in the tester (except if they look at OHLC[i-1] they can see the future.)

Indicators and EAs that look at other pair, do not work in the tester.

Indicators and EAs that look at other timeframes, you must have history for those timeframes and can not look at bar zero. Testing Features and Limits in MetaTrader 4 - MQL4 Articles

Reason: