There are other Timer elements or Timer implementations better than OnTimer() on MQL4?

 

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!

 
If you need multiple events, then schedule the nearest one in the event handler every time.
 
Ovo:
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 :


Orders

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.

 

Translate your timer into a real time i.e. if now is 14:39 and you want a 1 hour timer, make it 15:39.

Store these times in an array.

Run OnTimer() once per second, looping through your array to see if anything is due.

Once actioned, remove it from the array. 

 

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
Reason: