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 bar closes.