Does anyone know how to code a function that would make the program wait for candle close and then continue? Thanks in advance.

 
Does anyone know how to code a function that would make the program wait for candle close and then continue?
 
GreenPoint:
Does anyone know how to code a function that would make the program wait for candle close and then continue?
"wait" at what point ? it's very easy to return early on from start() just by checking the time of the candle . . . but it is actually impossible to detect the close of a candle . . you can detect the start of a candle though.
 

Just checking - program cycle of EA - New data - update chart - EA makes decisions based on new data and returns control to - wait for New data.

 
This function has been circulating around here for a while.
/**
* Checks if the bar has closed
* @param int  timeframe
* @param bool reset
*/
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);
}
 
I assume timefame would be 1,5,15,30,60,240. But what is bool reset? Thanks.
 
flaab:
This function has been circulating around here for a while.
Which I don't like because you can only call it once per tick. It fails if you call it more than once per tick and people tend to do that with function calls. Simpler:
int start(){
   static datetime Time0; if (Time0 == Time[0]) return(0);
   :
   Time0 = Time[0]; // \ Do this whenever you want to
   return(0);       // / wait for a new bar.
Reason: