// store previous open time
datetime timeprev=0; // global or static variable
// ------------
// check if previous open time is equal to current open time
if(timeprev == Time[0])
{
// it is equal, so lets skip this tick
return(0);
}
// not equal? so this mean new candle is formed
// lets save current open time
timeprev=Time[0];
// code to be executed only once per candle
...