Intrabar fills in backtests: stop or target first inside one bar?
A bar stores only open, high, low and close, so when one bar touches both the stop and the target the backtest cannot know which traded first and applies an assumption. Use the pessimistic setting (stop first), fill gapped orders at the open, and treat the gap between pessimistic and optimistic results as a measure of how much a strategy depends on intrabar luck.
By Soren Huang · Published · updated · Editorial policy
Contents
- How does a backtest decide whether a stop or target was hit first inside a bar?
- Why can one bar hit both the stop and the target?
- Pessimistic or optimistic: which fill assumption should you use?
- How are gap fills handled in a backtest?
- What is a bar magnifier and when do smaller bars resolve the order?
- How much do intrabar fill assumptions change results for tight-stop strategies?
- Frequently asked questions
- References
How does a backtest decide whether a stop or target was hit first inside a bar?
Intrabar fills in a backtest come from an assumption, not from data: a bar stores only its open, high, low and close, so when one bar touches both the stop and the target the software cannot know which traded first. The common default fills the stop first. Find out which assumption your software uses before trusting any report.
An intrabar fill is an order that executes at a price inside a bar's range rather than at its open or close. Stops and targets are the usual cases: a stop loss is a resting order to exit at a loss once price reaches a set level, and a profit target is a resting order to exit at a gain once price reaches a set level. When you replay rules on old prices, which is what backtesting in trading means, the software has four numbers per bar and no record of the path between them. It must therefore pick one of three ways to order the fills:
- Pessimistic: if both levels sit inside the bar's range, the stop filled first.
- Optimistic: if both levels sit inside the bar's range, the target filled first.
- Smaller-bar replay: open the bar into smaller bars of the same market and fill whichever level those smaller bars touch first.
The claim this article defends is simple: a strategy that only works under the optimistic assumption does not work. Everything below explains why that is the right standard and how to measure how far your own strategy is from it.
Why can one bar hit both the stop and the target?
One bar hits both levels whenever its range, the distance from low to high, is wider than the distance from the stop to the target. Think of a security camera that only photographs the room at the start and end of each hour and notes the highest and lowest point anyone reached. You know someone touched the ceiling and the floor during that hour; you do not know which came first.
Two things make this common. First, bar length: a 30-minute bar on an index future often spans more points than a day trader's stop and target combined, and a daily bar almost always does. Second, volatility: on fast days the same bar size covers far more range. The CFTC and SEC report on May 6, 2010 documents prices in the E-mini S&P 500 falling a long way and recovering within minutes, so any bar of fifteen minutes or longer from that afternoon contains a full round trip that its four prices hide completely. The same bar would fill a long trader's stop under one assumption and the target under the other.
The share of trades affected is a number you can measure. Count the bars in which both a resting stop and a resting target were inside the range while a position was open, and divide by the number of trades. A strategy where that share is near zero has almost no intrabar question. A strategy where it is a third of all trades is largely a bet on the fill assumption, and the next section shows how to price that bet.
Pessimistic or optimistic: which fill assumption should you use?
Use the pessimistic assumption for every decision, and run the optimistic one only to measure the gap. The pessimistic result is a floor: in live trading the real sequence can only match it or beat it. The optimistic result is a ceiling: live trading can only match it or fall short. The distance between the two is a direct measure of how much of the backtest depends on intrabar luck. Pardo (2008) makes the general case that a strategy evaluation should rest on conservative, realistic assumptions, and the fill order is one of the places where that principle has a concrete switch.
| Setting | When a bar touches both levels | Live trading compared with the report | What it needs |
|---|---|---|---|
| Pessimistic (stop first) | Fills the stop at the stop price | Can only match or beat the report | Nothing extra |
| Optimistic (target first) | Fills the target at the target price | Can only match or fall short of the report | Nothing extra |
| Smaller-bar replay | Fills whichever level the smaller bars touched first | Close to the report, except inside the smallest bar | Smaller-bar data for the whole test period |
Hypothetical example
A long entry at 100 with a target 8 points above at 108 and a stop 4 points below at 96. The next bar opens at 100, trades a high of 109 and a low of 95, and closes at 101. The pessimistic setting fills the stop: −4 points. The optimistic setting fills the target: +8 points. The 1-minute bars for that half hour show price reaching 95 at minute 7 and 109 at minute 22, so the smaller-bar replay also fills the stop: −4 points. One bar, a 12-point swing in the recorded result, and only the replay used information about what actually happened.
A practical routine: run the strategy twice with everything else unchanged, once pessimistic and once optimistic, and write down the net result of each. If the pessimistic run is still positive after costs and the optimistic run is less than about twice as large, the strategy's edge mostly lives outside the ambiguous bars. If the pessimistic run is negative and the optimistic run is strongly positive, the strategy is a fill-assumption strategy, and no amount of other validation repairs that.
How are gap fills handled in a backtest?
A realistic backtest fills a gapped stop or target at the next bar's open, not at the order price, because the order price never traded. A gap is a jump between one bar's close and the next bar's open with no trades in between, most often across the overnight break or a weekend. A stop that sits inside that jump is triggered by the first print beyond it, which is the open. The SEC's investor bulletin on stop orders makes the same point for live markets: a stop order becomes a market order when the stop price is reached, and in a fast or gapping market it can fill far from the stop price.
Hypothetical example
Day 1 closes at 500 with a long position open and a stop 10 points below at 490. Day 2 opens at 475 after overnight news. The correct fill is the open, 475, for a loss of 25 points. A backtest that fills at 490 records a loss of 10 points, which is 15 points better than any trader could have done, and it repeats that favour on every gap in the history.
Two consequences follow. First, a stop caps the loss only while the market trades through it, so overnight exposure carries a cost that no stop width can remove; include that in how you judge a strategy's drawdown. Second, gap handling is tied to the timing of every fill. A signal computed on a bar's close cannot fill on that same close, which is the most common of the look-ahead leaks in a backtest, and a stop cannot fill at a price the next bar skipped over. AlphaPrime (Valynox) applies next-bar execution and charges fees and slippage inside every evaluation in its backtesting, so a signal on today's close fills no earlier than tomorrow's bar, which is the first half of this discipline. The second half is your cost setting: slippage on a stop that fills in a gap or a fast market is larger than on a quiet limit entry, and the guide to commission and slippage in backtests explains how to set a figure that covers both.
What is a bar magnifier and when do smaller bars resolve the order?
A bar magnifier narrows the intrabar question but does not remove it. A bar magnifier is a backtest feature that replays each test bar with smaller bars of the same market, usually 1-minute or tick data, so that the order in which price reached the stop and the target can be read instead of assumed. In most bars this settles the question. Inside the smallest bar used, the same four-price problem returns, and the pessimistic or optimistic setting applies there.
- Find the ambiguous bar. A 30-minute test bar's range covers both the resting stop and the resting target.
- Open it. The same 30 minutes are loaded as thirty 1-minute bars.
- Walk forward through them. The first 1-minute bar whose range touches either level marks the fill, at that level's price.
- Apply the fallback. If that single 1-minute bar touches both levels, the chosen assumption decides, exactly as it would for the big bar.
Smaller bars resolve the order when the stop-to-target distance is wider than the typical range of the smaller bar. A 1-minute bar on an index future usually spans a few ticks; a stop and target 20 ticks apart will almost never both sit inside one, so the replay settles nearly every case. A 3-tick stop will still be ambiguous in a meaningful share of 1-minute bars, and tick data is then the only way further. Two costs come with the method: the smaller-bar data must cover the whole test period without gaps, and each bar takes many more computations to evaluate, so a search that tests many candidates runs more slowly on whatever processor or graphics card you use. A sensible order of work is to search and rank under the pessimistic setting, then replay only the finalists with smaller bars to see how much of the pessimistic penalty they recover.
How much do intrabar fill assumptions change results for tight-stop strategies?
The tighter the stop and target, the more bars touch both and the wider the spread between pessimistic and optimistic results, so a tight-stop strategy must pass under the pessimistic setting or it has not passed. A stop two ticks from entry on 5-minute bars will sit inside the range of most bars while the trade is open; a stop sixteen ticks away will sit inside few of them. The fill assumption therefore decides a large share of trades in the first case and almost none in the second.
Hypothetical example
One intraday rule on 5-minute bars, tested three times with the stop and target set at 4, 8 and 16 ticks from entry, costs included. With 4-tick levels, 38% of the trades had a bar that touched both; the pessimistic net result is −$1,900 and the optimistic +$6,200, a gap of $8,100 between floor and ceiling. With 8-tick levels, 17% of trades are ambiguous; pessimistic +$900, optimistic +$3,400. With 16-tick levels, 5% are ambiguous; pessimistic +$1,500, optimistic +$1,800. Only the 16-tick version has a result the fill setting barely moves, and only the 8- and 16-tick versions are positive on the floor.
The same effect shows up outside futures. Intraday stops on cash equities face the same four-price problem, and the costs are higher per trade, which is why Taiwan cash day trading backtests need both the pessimistic fill and a full cost line before their result means anything. To turn tick distances into money for your own contract, the free futures contract calculator gives the tick value and the profit or loss of a trade.
The opposite case is a rule with no resting stop or target at all. When every entry and exit is a signal on the bar's close and fills on the next bar's open, there is no intrabar ordering question: the fill price is the open, and the only things that move the result are the open prices and the cost per trade. The run below is that case. It tested ES daily bars from 2019-01-02 to 2025-06-30, long and short, one contract, with an ATR Channel rule as the only entry and exit, no stop, no target and no filters. The rule is a stand-in built from standard indicators (the ATR sets the channel width), not the subject of this article; it is here because its fills are unambiguous.
Source: AlphaPrime product engine (CPU), run 2026-10-31. ES daily bars, 2019-01-02 to 2025-06-30, long and short, 1 contract, $20 commission and $25 slippage per trade.
| Number | Result |
|---|---|
| Net profit (closed trades) | $78,397.5 |
| Max drawdown | $56,087.5 |
| Trades | 32 |
| Win rate | 50% |
| Profit factor | 1.881 |
| Average trade | $2,449.92 |
| Time in market | 95.68% |

Read these numbers for what they are. This is the one candidate the search kept out of the 1,024 it tried, chosen for its return against its drawdown, and picking the kept one after the fact flatters it; the other candidates did worse, and the best of many tries always carries a selection bonus. Thirty-two trades is a small sample, and a $56,087.5 drawdown against $78,397.5 of net profit is a deep hole relative to the gain. None of it says what the ATR Channel will earn or what a reader can expect. What the box does show is a report whose result moves only with the open prices and the $45 of cost per trade, which is the contrast with the tight-stop example above, where the 4-tick version of the same rule swung from a loss to a gain several times that size depending on one setting.
Your next step: open your current strategy's settings, note which fill assumption is active, and run it twice with that one switch flipped and nothing else changed. Write the two net results side by side, then count how many trades had a bar touching both levels. If the pessimistic run fails or the two results differ by more than you decided in advance was acceptable, widen the levels or move the exit to the next bar's open and test again before any other validation step.
Frequently asked questions
What happens when stop and target are hit in the same bar?
The backtest cannot tell which was reached first, because a bar records only open, high, low and close. It applies a setting: pessimistic software fills the stop, optimistic software fills the target, and software with a bar magnifier reads smaller bars to find the real order. Check the setting before reading any report, and prefer the pessimistic one for decisions.
What is a bar magnifier in backtesting?
A bar magnifier replays each test bar with smaller bars of the same market, such as 1-minute bars inside a 30-minute bar, and fills whichever level the smaller bars touched first. It resolves the stop-or-target order in most bars. Inside the smallest bar used, the ordering assumption still applies, so it narrows the uncertainty rather than removing it, and it needs complete smaller-bar data for the whole period.
How are gap fills handled in a backtest?
A realistic backtest fills a stop or target that was jumped by a gap at the next bar's open, because the order price never traded. Filling at the order price records a better trade than anyone could have had and repeats that favour on every gap. The loss on a gapped stop is therefore larger than the stop distance, and no stop width can cap it.
Do intrabar assumptions change backtest results?
Yes, in proportion to how often one bar covers both the stop and the target. For a rule with levels a few ticks from entry on intraday bars, the assumption can decide a third or more of all trades and flip the net result from a loss to a gain. For a rule with wide levels, or one that exits on the next bar's open with no resting orders, the assumption changes almost nothing. Run both settings and compare the two results to see where your strategy sits.
References
- Pardo, R. (2008). The Evaluation and Optimization of Trading Strategies (2nd ed.). John Wiley & Sons.
- Staffs of the CFTC and SEC (2010). Findings Regarding the Market Events of May 6, 2010. Report to the Joint Advisory Committee on Emerging Regulatory Issues, September 30, 2010.
- U.S. Securities and Exchange Commission. Stop, Stop-Limit, and Trailing Stop Orders (Investor Bulletin). https://www.investor.gov/introduction-investing/general-resources/news-alerts/alerts-bulletins/investor-bulletins-15

