EA process on bar close

 
Is it possible to have an EA only run on a bar close of the chart?

Thanks in advance,

Ed
 

I wrote the following sophisticated function to check for bar close:

int init()
{
// if you don't want to execute on the first tick
  IsBarClosed(-1,false);
}
 
int start()
{
// check if bar is closed
  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);
}
 
Thanks.
 

Thank aswell.. you rock! :)

Reason: