iTime not working as expected

 

Suppose i start some EA in 1h time frame, and then some where in the code the isNewBar() function gets called, it will Print 28-12-2018 22:00:00 for instance...

And then i change the time frame to 1m and then the isNewBar() function keeps printing 28-12-2018 22:00:00

I was expecting something like 28-12-2018 22:48:00


Can please someone clear my mind?

Thank you!!!

bool isNewBar() {

    static  datetime previousCandleTime = 0; 
            datetime currentCandleTime  = iTime(Symbol(), Period(), 0);
    
    Print(currentCandleTime);  // testing purpose
    
    if (previousCandleTime != currentCandleTime) {
    
        previousCandleTime = currentCandleTime;  
        return true;
    } 
    

    return false;
}
 
Anyone please!?
 
  bool NewBar()
  {
   static datetime LastTime = 0;
   bool ret = Time[0] > LastTime && LastTime > 0;
   LastTime = Time[0];
   return(ret);
  }
 

Genesis Hafalla

I suppose that it would work on an indicator but i need to implement this function on an expert advisor.


Thank you for your reply

 

Maybe it's something in iTime(). Not sure.

I use SERIES_LASTBAR_DATE in my comparison, not iTime().

https://www.mql5.com/en/articles/159

Reason: