Live Log in Start free

Stop or target first? The same-candle problem in backtesting

When one bar's range covers both your stop and your target, OHLC data cannot say which was hit first. How simulators guess, and how to keep the guess from flattering you.

Published
Reading
3 min
Sections
3
By
Backcandle team
Feed
RSS →

A long trade has its stop 1% below entry and its target 2% above. The next one-hour bar has a low below the stop and a high above the target. Did the trade win or lose?

From the bar alone you cannot know. A candle records four prices — open, high, low, close — and nothing about the order the high and low happened in. Every backtest and every simulator that works from candles has to guess.

The common guesses

  • Target first. The most flattering choice, and the one to be suspicious of. A backtest that resolves ambiguous bars this way overstates every strategy with tight stops.
  • Stop first. The pessimistic choice. Safe for judging a strategy, slightly unfair to it.
  • Nearest extreme first. Assume the price went first to whichever of the high and the low is closer to the open, then to the other, then to the close. This matches how bars usually form, but it is still a guess.
  • Look at a lower timeframe. The honest answer when the data exists: zoom into the minutes inside the bar and see what happened.

What Backcandle does

The simulator walks each bar along the nearest-extreme path — open, then the closer of high and low, then the other, then close — and fills every order and trigger in the order that path crosses them. A take-profit fills at its level. A stop-loss is treated as a market order once triggered and fills with a small amount of adverse slippage, kept inside the bar's range. If the market gaps through a level between bars, the order fills at the gapped open, not at the level.

That is a reasonable model, not a recording of the tape. On a bar where your stop and target both sit inside the range, the outcome is the model's call.

How to keep ambiguous bars from flattering you

  • Count them. If a meaningful share of your trades resolve on a bar that touched both levels, the result depends on the fill model more than on your strategy.
  • Trade a lower timeframe for the exit. On a 5-minute chart, far fewer bars span both a stop and a target that were sized for a one-hour setup. Backcandle lets you switch timeframe mid-session.
  • Re-score them pessimistically. For a robustness check, count every ambiguous bar as a loss. If the edge survives that, it was not an artifact.
  • Widen the gap between stop and target relative to bar size. Targets well outside the typical bar range rarely land in the same candle as the stop.

For the related question of how much data a result needs, see how many trades you need before you trust a backtest.

Keep reading

More from
the team.