Only one timer is allow in one Expert Advisor

To add comments, please log in or register
nicolasxu
312
nicolasxu  

https://www.mql5.com/en/docs/eventfunctions/eventsettimer

From the doc, I can see there is no timer ID. No way to tell which is which, so there is only one timer is allowed in each EA?

Documentation on MQL5: Working with Events / EventSetTimer
Documentation on MQL5: Working with Events / EventSetTimer
  • www.mql5.com
Working with Events / EventSetTimer - Reference on algorithmic/automated trading language for MetaTrader 5
Stanislav Korotky
31575
Stanislav Korotky  
nicolasxu:

https://www.mql5.com/en/docs/eventfunctions/eventsettimer

From the doc, I can see there is no timer ID. No way to tell which is which, so there is only one timer is allowed in each EA?

Usually one timer with lesser period is sufficient to invoke all tasks with larger periods. What is your usecase that requires many timers?
nicolasxu
312
nicolasxu  
marketeer:
Usually one timer with lesser period is sufficient to invoke all tasks with larger periods. What is your usecase that requires many timers?
Thanks for confirming this for me. I just feel as a script language, MQL should allow multiple timers, like Javascript. 
Alain Verleyen
38980
Alain Verleyen  
nicolasxu:
Thanks for confirming this for me. I just feel as a script language, MQL should allow multiple timers, like Javascript. 
What to do ?
Stanislav Korotky
31575
Stanislav Korotky  
nicolasxu:
Thanks for confirming this for me. I just feel as a script language, MQL should allow multiple timers, like Javascript. 
JavaScript is based on closures in a great degree (every timer possesses a function object for deferred execution). MQL5 is not.
Stanislav Korotky
31575
Stanislav Korotky  
BTW, you may consider a timer (conceptually) as an additional thread. BUT, in MQL5 there is only 1 thread per EA. So there is only 1 timer.
Alain Verleyen
38980
Alain Verleyen  
marketeer:
BTW, you may consider a timer (conceptually) as an additional thread. BUT, in MQL5 there is only 1 thread per EA. So there is only 1 timer.
Yes and as you said earlier, you can use a lesser period. I am curious why nicolasxu needs multiple timers.
nicolasxu
312
nicolasxu  

angevoyageur:
Yes and as you said earlier, you can use a lesser period. I am curious why nicolasxu needs multiple timers.

 

To be honest, I have have specific plan for multiple timers now:)
Ex Ovo Omnia
3558
Ex Ovo Omnia  
nicolasxu:
To be honest, I have have specific plan for multiple timers now:)

I am using multiple timer events implementation. The pattern is in using the built-in timer for scheduling only the first event, and after triggered and ran the timer event handler, it reschedules the timer for the next nearest event. It works well.

And considering the concurrent timer thread - it is not possible unless there is implemented some mechanism for synchronized multiple-thread access to objects.

To add comments, please log in or register