Advertisement IC Markets

Using OnTimer for session logic instead of OnTick

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 806
Joined: Sun Oct 18, 2026 12:25 pm

Using OnTimer for session logic instead of OnTick

Post by FXS London Scalper »

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:
  • 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.
The biggest gain was the end of day close. On one illiquid symbol, my old code closed positions minutes after the intended time because no ticks arrived. Now it closes within a second.

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?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Post Reply