Search code examples
mql5

What can i use in place of TimeSeconds() in mql5?


I used TimeSeconds(opening time of any candle selected) in mql4 to track the current seconds as it is changing. i used it to set my Alert() to sound only twice. Now i want to do the same thing in Mql5, then i discover that mql5 does not have TimeSeconds(). How can i go about it?

The following code was what i used in mql4.

datetime myTime = iTime(_Symbol,_Period,0);
int currentMinute = TimeMinute(TimeCurrent());
int openMinutesOfLastCandle = TimeSeconds(myTime);

Solution

  • #ifdef __MQL5__
       int TimeSeconds(const datetime date)
         {
          MqlDateTime dt;
          TimeToStruct(time,dt);
          return dt.sec;
         }
    #endif
    

    Alternative would be to use TimeCurrent()%60 to get seconds.