Tick vs Closed-Bar Breakout Detection in MQL5: Why It Changes Your Backtests

21 November 2026, 15:50
Frederic Jean Andre Jouillerot
0
6

Most breakout Expert Advisors I review share one silent assumption: the breakout is detected the moment price touches the level. It feels responsive. In the Strategy Tester it often looks better. Live, it is one of the most common reasons a breakout EA bleeds through small losses.

This post compares tick-based and closed-bar breakout detection in MQL5: what changes in the logic, what changes in backtests, and how to implement closed-bar detection cleanly.

1. Two ways to define "a breakout happened"

Tick-based: on every tick, compare the current Bid or Ask with the channel high or low. As soon as price crosses, the signal fires.

Closed-bar: wait until the bar is finished, then compare its close with the channel built from the bars before it. The signal can only fire once per bar, on the first tick of the next bar.

The difference sounds cosmetic. It is not. A tick-based rule treats every wick as a breakout. A closed-bar rule only accepts bars that actually finished beyond the level.

2. Why the wick matters

Breakout levels are exactly where stops and pending orders accumulate. Price regularly pokes through a range high, triggers those orders, then closes back inside the range. A tick-based EA enters on the poke. A closed-bar EA sees a bar that closed inside the range and does nothing.

Over hundreds of trades, those avoided "wick entries" are often the difference between a breakout system with a positive expectancy and one that slowly gives back its winners.

3. The backtest trap

Tick-based logic is also the most sensitive to how the tester models price inside a bar:

  • In "1 minute OHLC" or "Open prices only" modes, intrabar paths are approximated. A tick-based breakout can fire on price movements that never happened in that order.
  • Even with "Every tick based on real ticks", spread widening around news is rarely reproduced exactly as your broker will deliver it live.

Closed-bar logic is much more robust to this: the decision depends on the close of a finished bar, which is the same in every modelling mode. If your EA only acts on closed bars, a backtest run in "Open prices only" is a reasonable first approximation of the signal logic, and a real-ticks run mostly refines execution costs. That is a big practical advantage when you validate across many symbols and years.

4. Implementing closed-bar detection in MQL5

The standard pattern is a new-bar check at the top of OnTick() , then signal evaluation on bar index 1 (the last closed bar):

datetime g_lastBar = 0;

bool IsNewBar(const ENUM_TIMEFRAMES tf)
  {
   datetime t = iTime(_Symbol, tf, 0);
   if(t == 0)              // history not ready yet
      return(false);
   if(t == g_lastBar)
      return(false);
   g_lastBar = t;
   return(true);
  }

void OnTick()
  {
   if(!IsNewBar(PERIOD_H1))
      return;

   int    n   = 20;   // channel length
   int    hiI = iHighest(_Symbol, PERIOD_H1, MODE_HIGH, n, 2);
   int    loI = iLowest (_Symbol, PERIOD_H1, MODE_LOW,  n, 2);
   double hi  = iHigh(_Symbol, PERIOD_H1, hiI);
   double lo  = iLow (_Symbol, PERIOD_H1, loI);
   double c1  = iClose(_Symbol, PERIOD_H1, 1);   // last CLOSED bar

   if(c1 > hi) { /* upside breakout confirmed on close */ }
   if(c1 < lo) { /* downside breakout confirmed on close */ }
  }

Three details that matter:

  • The channel starts at index 2, so the bar being tested (index 1) is not part of the channel it is supposed to break.
  • Guard against iTime() returning 0 when history is not loaded yet, otherwise the EA can "detect" a new bar on startup and act on garbage.
  • Store the last processed bar persistently if your EA can be reloaded mid-bar (terminal restart, parameter change), so the same bar is not evaluated twice.

5. The trade-off, honestly

Closed-bar confirmation is not free:

  • You enter later, often at a worse price than the level itself.
  • On a strong impulse bar, the stop distance can be larger, which means a smaller position for the same risk.
  • Some fast moves are simply missed.

What you get in exchange is a signal that is stable across backtest modes, far fewer wick entries, and behaviour that is identical in testing and live. For a system meant to run unattended, that consistency is usually worth more than a few pips of entry price. But it remains a hypothesis to validate on your own symbols, not a law.

6. How we apply it

Titan Breakout, the H1 breakout EA we develop at Pipmaster France, only evaluates breakouts on closed H1 candles, never on ticks, and then applies trend, strength and market-condition filters before any order is sent. It is free to download for backtesting and demo, so you can compare closed-bar behaviour on your own broker data: Titan Breakout (free backtest and demo).

Trading leveraged products involves a high risk of capital loss. Backtest results, real or simulated, do not guarantee future performance.