If you need multiple events, then schedule the nearest one in the event handler every time.
Not works because the problem is simulate different expirity times on the same graphic, then more than one expiration can occurs at the same time. See the timeline below :
And there may be many orders in different time expiration time that expires at the time, next and even in large spaces of time between them.
I don't know how to implement this simulation, because there are no opened orders.
Ok, understand... I'm doing it just now...
it does not matter how many events appear in the same time. Check them all. I use timers a lot, for asynchronous requests in pipes or http, for chart objects check, for history data periodic check, whatever. The timer handler first runs all the events, which exceeded their execution time, and then reschedules the timer for the next event. I absolutely do not care how many events there are, and the events get triggered with PC clock precision. Here is an example log entry with one event executed and setting the timer for the next one by comparing their execution times.
2015.06.10 13:41:19 TRACE: OnTimer() >>(IN) @MT4IndicatorManager.class.mqh:213 2015.06.10 13:41:19 TRACE: MT4BaseManager.onTimer() >>(IN) @MT4BaseManager.class.mqh:172 2015.06.10 13:41:19 TRACE: MT4TimerSingleListener.run() >>(IN) @MT4TimerEvent.class.mqh:102 2015.06.10 13:41:19 TRACE: ButtonCheckTimerHandler.run() >>(IN) @MT4ButtonRow.class.mqh:41 // only one event executed 2015.06.10 13:41:19 TRACE: ButtonCheckTimerHandler.run() >>(OUT) @MT4ButtonRow.class.mqh:46 2015.06.10 13:41:19 TRACE: MT4TimerSingleListener.run() >>(OUT) @MT4TimerEvent.class.mqh:106 2015.06.10 13:41:19 TRACE: MT4BaseManager.onTimer() >>(Scheduling next event in -571700907 ms.) @MT4BaseManager.class.mqh:211 2015.06.10 13:41:19 TRACE: MT4BaseManager.onTimer() >>(Scheduling next event in 2953 ms.) @MT4BaseManager.class.mqh:211 2015.06.10 13:41:19 TRACE: MT4BaseManager.onTimer() >>(Scheduling next event in 2953 ms.) @MT4BaseManager.class.mqh:211 2015.06.10 13:41:19 TRACE: MT4BaseManager.onTimer() >>(Scheduling next event in 2953 ms.) @MT4BaseManager.class.mqh:211 2015.06.10 13:41:19 TRACE: MT4BaseManager.onTimer() >>(Scheduling next event in 1469 ms.) @MT4BaseManager.class.mqh:211 2015.06.10 13:41:19 TRACE: MT4BaseManager.onTimer() >>(Scheduling next event in 19 ms.) @MT4BaseManager.class.mqh:211 // this one determines schedule 2015.06.10 13:41:19 TRACE: MT4BaseManager.onTimer() >>(OUT) @MT4BaseManager.class.mqh:223 2015.06.10 13:41:19 TRACE: OnTimer() >>(OUT) @MT4IndicatorManager.class.mqh:227

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Greetings from Brazil!
MQL4 has other TIMER elements in addition to the OnTimer() function ?
I am making a simulation EA for Binary Options, and need to simulate (not open real orders)... then, need to define the open/close interval and on simulation need to check the price to know if the simulated order has win/lost.
The OnTimer not works on this case, because there may be different open orders in different expiration times!