MQL5 OnTick vs OnTimer: How to Use Each in EA Design
Contents
Bottom line: decide on the new bar, handle time-based tasks in OnTimer
Here is the conclusion up front. If your EA trades on a longer timeframe such as H1 or H4, it is enough to make trading decisions only on the first tick of a new bar. Repeating the same calculation on every tick just uses CPU without changing the decision. For work that has to run even when no ticks arrive, use OnTimer. Examples are writing out state over the weekend or tidying up orders at a set time of day.
That said, which approach is right depends on the strategy. This article explains how the two mechanisms differ and what someone choosing an EA can verify.
Recommended Broker Comparison →
🎁 Download Free EA📧 Free 8-email course + subscriber-only pack of 13 MT5 indicators
Right after you sign up, you get a download link for a subscriber-only pack of our 13 MT5 indicators: compiled files (.ex5), source code and a setup guide. Then 8 emails on algo-trading essentials, reading backtests correctly and choosing a broker (one a day for the first 5 days, then 7, 14 and 30 days after signing up). You also get notified before each price rise of the versions sold on the MQL5 Market (launch pricing that steps up as copies sell). Our EAs are free on this site with a live account at a partner broker.
* Privacy strictly protected. You can unsubscribe at any time.
How they work: tick-driven vs time-driven
OnTick (tick-driven)
OnTick is called every time a new price (tick) arrives for the symbol the EA is running on. During fast markets it can be called many times per second, and over a weekend, when the market is closed, it is never called.
There is one behavior you should know about. A tick that arrives while the previous OnTick call is still running is not queued. It is skipped. In other words, an EA with heavy per-call processing will miss ticks in the middle of a sharp move.
OnTimer (time-driven)
OnTimer is called at the interval you set with EventSetTimer(). It runs regardless of price movement, so it is called even while the market is closed. An EA gets only one timer, and if processing backs up, events are skipped in the same way. There is also no guarantee that it fires exactly on the specified interval.
| Item | OnTick | OnTimer |
|---|---|---|
| Trigger | Price update | Elapsed time |
| While the market is closed | Not called | Called |
| Call frequency | Higher in volatile markets | Roughly constant |
| Suited for | Entry and exit decisions | Periodic aggregation, time-based tasks |
| Main caution | Heavy processing causes missed ticks | Runs even when no new price has arrived |
Writing low-frequency strategies without wasting CPU
For a strategy that decides on H4, OnTick may be called thousands of times during the four hours a bar lasts, but the closed-bar values used for the decision never change. So our basic pattern is to let the heavy processing through only when the bar changes, as shown below.
datetime g_lastBar = 0;
void OnTick()
{
datetime cur = iTime(_Symbol, PERIOD_H4, 0);
if(cur == g_lastBar) return; // do nothing while on the same bar
g_lastBar = cur;
// make the decision here using the closed bar (shift 1)
}
It also matters to create indicator handles once in OnInit rather than rebuilding them on every OnTick. If you use OnTimer, stop the timer by calling EventKillTimer() in OnDeinit.
When you run EAs on several charts on a VPS, these differences show up as CPU load. Our thinking on choosing a VPS is summarized in VPS information.
What EA buyers can check
Even if you cannot see the code, you can verify the following points to a certain extent.
- Description and parameters: Is there a setting such as "decide only on a new bar"?
- VPS CPU usage: If load drops clearly when you remove one EA, it may be running heavy processing on every tick.
- Expert log: Check whether identical output lines appear on every tick.
- Tester results: An EA that decides on the bar's open price should give broadly similar results in "Open prices only" and "Every tick" modes. If they differ a lot, the EA is also reacting to intra-bar price movement.
For the basics of installing and configuring an EA, see How to set up an EA.
Limits and caveats
Here are the less convenient points.
- Intra-bar risk is not monitored: If decisions are limited to new bars, the EA will not react to sudden moves in the middle of a bar. Unless the stop loss is built in as a stop order attached to the position, you can end up accepting unexpected losses.
- Delay at the new bar: Even after a new bar forms, nothing runs until the first tick of that bar arrives. On quiet symbols or in quiet hours, the decision can come later than the start of the bar.
- OnTimer behaves differently in the tester: In the tester the timer fires on virtual time, so the intervals do not necessarily match those on a live account.
- Lighter processing does not improve results: Reducing CPU load does not make an EA more profitable. Whether a strategy is good is a separate question.
The design differences are harder to see in low-trade-count H4 EAs such as ETHEREUM EA. Still, what you can verify from the outside has limits. What we can state with certainty is only what concerns the code we wrote ourselves.
Summary
- OnTick is called when a price arrives, and OnTimer is called at a fixed interval
- Events that arrive during processing are skipped, not queued. Heavy processing leads to missed events
- For low-frequency strategies, deciding only on a new bar avoids wasting CPU
- Use OnTimer for work that must run even in periods with no ticks
- Prepare for intra-bar risk with stop orders. Lighter processing does not raise performance
- More know-how is collected in EA and MT5 know-how
Related
2026-07-07
MT5 AutoTrading Disabled (10027 / 10026): 4 Switches to Check
2026-07-07
MT5 'Invalid Stops' Error (10016 / 130): 6 Causes and the Fix for Each
2026-07-07
MT5 'Market Closed' Error (10018 / 132) on a Weekday: Causes and Fix
2026-07-07
Off Quotes & Requote in MT5: Fix Errors 10021 / 10004
📧 Free 8-email course + subscriber-only pack of 13 MT5 indicators
Right after you sign up, you get a download link for a subscriber-only pack of our 13 MT5 indicators: compiled files (.ex5), source code and a setup guide. Then 8 emails on algo-trading essentials, reading backtests correctly and choosing a broker (one a day for the first 5 days, then 7, 14 and 30 days after signing up). You also get notified before each price rise of the versions sold on the MQL5 Market (launch pricing that steps up as copies sell). Our EAs are free on this site with a live account at a partner broker.
* Privacy strictly protected. You can unsubscribe at any time.
Have a question about EAs or FX?
You can post it on the Nattzy trading forum (free sign-up). Questions beyond this article are welcome too — EA settings, choosing a broker and more.
Ask on Nattzy ↗