Run once per candle in MQL5

rhodium1trading
20
rhodium1trading  

Hi.. I want a function to run only once at the beginning of each candle. One told me that the following code will do it in MQL4.


 if(IsNewCandle())
 {
 //---Here comes the function which needs to run only at the beginning of each candle---//
 }
 
 bool IsNewCandle()
 {
      static datetime saved_candle_time;
      if(Time[0]==saved_candle_time)
      return false;
      else
      saved_candle_time=Time[0];
      return true;
 }   


Can someone please help me to code the same in MQL5? Thanks! 

William Roeder
24230
William Roeder  
rhodium1trading: Can someone please help me to code the same in MQL5?

Replace the predefined variable Time[] with the iTime() function.

rhodium1trading
20
rhodium1trading  
William Roeder:

Replace the predefined variable Time[] with the iTime() function.

Thanks!