Using OnTimer for session logic instead of OnTick
Posted: Fri Oct 30, 2026 9:45 am
My EAs used to check session times inside OnTick. That works on busy pairs, but on a quiet market the first tick after 08:00 might come a few seconds late, and on some symbols there can be gaps of a minute or more.
I moved all time-based logic to OnTimer, set with EventSetTimer(1) in OnInit:
One caution: the timer doesn't fire in the strategy tester the same way as live, so I test time logic separately in visual mode.
Do others split timer and tick logic like this, or keep everything in OnTick?
I moved all time-based logic to OnTimer, set with EventSetTimer(1) in OnInit:
- Session start and end flags, the daily reset, and the end of day flat rule all run in the timer.
- OnTick only handles price-based logic: signals, stops, trailing.
- The timer uses TimeTradeServer() and converts to UTC with a fixed offset table, because TimeCurrent() only updates with ticks.
One caution: the timer doesn't fire in the strategy tester the same way as live, so I test time logic separately in visual mode.
Do others split timer and tick logic like this, or keep everything in OnTick?