Random Issue with an EA
This looks like sometimes you detect a new hour, but the bars did not shift so far. Could maybe happen on the very first few ms of the new hour. Try this fix:
int BarCount; void OnInit() { BarCount=-1; // reset ... } void OnTick() { if(Bars(_Symbol,PERIOD_H1))!=BarCount && BarCount!=-1) { ... // new bar } BarCount=Bars(_Symbol,PERIOD_H1); }
That is not a good example.
Bar number can vary due to download of history.
Use Time instead.
//--- system variable datetime bartime=0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- set bartime bartime!=iTime(Symbol(),PERIOD_H1,0); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- check time if(bartime!=iTime(Symbol(),PERIOD_H1,0)) { Alert("New Bar!"); bartime!=iTime(Symbol(),PERIOD_H1,0); // overwrite old value } } //+------------------------------------------------------------------+
This looks like sometimes you detect a new hour, but the bars did not shift so far. Could maybe happen on the very first few ms of the new hour. Try this fix:
Thanks for your reply, I will try this one.
That is not a good example.
Bar number can vary due to download of history.
Use Time instead.
Thanks for your reply, I will try this one as well...
Hello EA Guru,
I have coded an EA and it is under test on demo account. I have noticed that sometimes EA dont open the valid trade. Further investigation reveals that EA is taking wrong candle value (open & close) for processing the entry rules. To elaborate further, as per rule EA executes all code at each hour (when an hour completes i.e. new hour just starts & new candle just opens up, the EA executes) and supposed to read open & close value of previous candle. But whenever issue happens I have noticed that EA reads open & close value of a candle which is printed before the previous candle (e.g. end of 11th hour which is nothing but beginning of 12th hour, 12th candle opens, EA supposed to read 11th candles open & close price however sometimes it read open & close value of 10th candle).
Any idea why I am facing this issue?