OnTimer versus OnTick for a scalping EA
Posted: Mon Oct 19, 2026 9:05 am
OnTimer versus OnTick for a scalping EA
Most MQL EAs put everything in OnTick, because that's what the templates do. For a scalping EA I'd split the work between OnTick and OnTimer, and being clear about why.
OnTick runs when a new tick arrives on the chart symbol. That's the right place for anything that reacts to price: checking whether an entry condition is met, managing a stop, reading the spread at the moment of entry.
OnTimer runs on a schedule you set with EventSetTimer, in seconds, or EventSetMillisecondTimer. It runs whether ticks arrive or not. That makes it the right place for anything tied to the clock rather than price. Closing all trades at a fixed session end time. Checking a news calendar file. Writing a heartbeat to a log so you know the EA is alive. Scanning other symbols that aren't on the chart.
The classic bug of putting time based logic in OnTick is that it only runs when a tick arrives. On a quiet pair late in the day, ticks can be several seconds apart, so a close at exactly 16:00 might happen at 16:00:07. Usually harmless. During the rollover hour, with ticks very sparse, it can be much later.
Kill the timer in OnDeinit with EventKillTimer. Forgetting it is a common source of strange behaviour after reloading the EA.
Most MQL EAs put everything in OnTick, because that's what the templates do. For a scalping EA I'd split the work between OnTick and OnTimer, and being clear about why.
OnTick runs when a new tick arrives on the chart symbol. That's the right place for anything that reacts to price: checking whether an entry condition is met, managing a stop, reading the spread at the moment of entry.
OnTimer runs on a schedule you set with EventSetTimer, in seconds, or EventSetMillisecondTimer. It runs whether ticks arrive or not. That makes it the right place for anything tied to the clock rather than price. Closing all trades at a fixed session end time. Checking a news calendar file. Writing a heartbeat to a log so you know the EA is alive. Scanning other symbols that aren't on the chart.
The classic bug of putting time based logic in OnTick is that it only runs when a tick arrives. On a quiet pair late in the day, ticks can be several seconds apart, so a close at exactly 16:00 might happen at 16:00:07. Usually harmless. During the rollover hour, with ticks very sparse, it can be much later.
Kill the timer in OnDeinit with EventKillTimer. Forgetting it is a common source of strange behaviour after reloading the EA.