Run once per candle in MQL5

 

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! 

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

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

 
William Roeder:

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

Thanks!
 

I used the above and it worked. Thanks again for the help!

But there's a small concern. When the alert sends a positive signal, can we skip analyzing the particular symbol on the chart for several candles? Otherwise it sends the same alert again and again at the beginning of each candle. Please help.  

 
rhodium1trading:

can we skip analyzing the particular symbol on the chart for several candles? 

the program doesn't understand "several".
code your logic (skip candle etc) in

if(IsNewCandle()) {
        //---Here comes the function which needs to run only at the beginning of each candle---//
}