When programming an MT4 robot, you often need to perform certain actions only at the beginning of a new candle. This can be either for execution speed reasons or because of the logic flow of your trading system.
Here is a boolean (true/false) MQL4 function that returns true whenever a new candle has closed/opened on the given timeframe:
bool IsNewCandle(int tf=0)
{
static datetime timeLastCandle=0;
if(iTime(Symbol(),tf,0)==timeLastCandle)
return (false);
timeLastCandle=iTime(Symbol(),tf,0);
return(true);
}
Let me know if you would have done it differently.