Is there any function for testing Candle Bar closed in MQL5?

To add comments, please log in or register
jaffer wilson
1460
jaffer wilson  

I have tried the following code in MQL5 but getting errors. This code was I guess from MQL4.

Code:

int OnInit()
{
// if you don't want to execute on the first tick
  IsBarClosed(-1,false);
  return(1);
  if(!IsBarClosed(0,true)) // true/false here allows to keep old bar for check again later in the code and reset
      return(0);
}
 
 
//+------------------------------------------------------------------+
//| check if new bar has formed
//+------------------------------------------------------------------+
bool IsBarClosed(int timeframe,bool reset)
{
    static datetime lastbartime;
    if(timeframe==-1)
    {
        if(reset)
            lastbartime=0;
        else
            lastbartime=iTime(NULL,timeframe,0);
        return(true);
    }
    if(iTime(NULL,timeframe,0)==lastbartime) // wait for new bar
        return(false);
    if(reset)
        lastbartime=iTime(NULL,timeframe,0);
    return(true);
}

Output:

'iTime' - function not defined  testing lines and trdae.mq5     243     25
'iTime' - function not defined  testing lines and trdae.mq5     246     8
'iTime' - function not defined  testing lines and trdae.mq5     249     21
3 error(s), 0 warning(s)                4       1

Kindly, help me in getting it done correctly with MQL5. I am trying to detect the Candle Bar closing time and not opening time. I just want to attempt when the candle bar closes.

William Roeder
19818
William Roeder  
There is no such function (iTime) in MQL5. Code the equivalent.
          Migrating from MQL4 to MQL5 - MQL5 Articles № 18
To add comments, please log in or register