Download MetaTrader 5

OnTimer question

To add comments, please log in or register
John May
3811
John May  

Does anyone know how to access what time remains before the next OnTimer event occurs? 

I know I can  calculate it from when the event timer is set. But is there another way? I did not see anything in the documentation.

Thank you 

Alain Verleyen
Moderator
32022
Alain Verleyen  
CappinJack:

Does anyone know how to access what time remains before the next OnTimer event occurs? 

I know I can  calculate it from when the event timer is set. But is there another way? I did not see anything in the documentation.

Thank you 

Why do you need this ? One solution : you can set a global variable (datetime) in the OnTimer event handler and check elapsed time comparing this variable with current time.
Documentation on MQL5: Date and Time / TimeCurrent
Documentation on MQL5: Date and Time / TimeCurrent
  • www.mql5.com
Date and Time / TimeCurrent - Documentation on MQL5
John May
3811
John May  
angevoyageur:
Why do you need this ? One solution : you can set a global variable (datetime) in the OnTimer event handler and check elapsed time comparing this variable with current time.

That is what I did.  I  use the timer event it to update some external parameters and write some files. I display the time remaining, mostly because I am curious. I started with an input variable:

input int   Opti_Sec=4;                    // hours between parameter check

 I declared a global variables:

   datetime          lastontimer;     // last ontime event 

 The I set it to the local time in the OnInit and Ontimer functions:

   lastontimer=TimeLocal();

 And when I wanted to display it, I just use the local time to calculate the time remaining:

   string cmt="Time to Next Update: "+TimeToString((Opti_Sec*60*60)-(TimeLocal()-lastontimer),TIME_SECONDS)+"\n";
Alain Verleyen
Moderator
32022
Alain Verleyen  
CappinJack:

That is what I did.  I  use the timer event it to update some external parameters and write some files. I display the time remaining, mostly because I am curious. I started with an input variable:

 I declared a global variables:

 The I set it to the local time in the OnInit and Ontimer functions:

 And when I wanted to display it, I just use the local time to calculate the time remaining:

Good. I don't think there is something natively provided in MT5.
To add comments, please log in or register