How to Algo

Backtesting Limit Orders: A Touch Is Not a Fill

Why a resting limit order touched in a backtest often doesn't fill live: queue position, trade-through rules and adverse selection, measured on futures.

Part 7 of 20 · How to Algo · Previous: Lookahead bias · Next: Trading costs

When the low of a bar equals your buy limit, the bar tells you that someone traded at that price. It does not tell you that you did. Orders at a price are filled in the order they arrived, and a single print at your level may have used up only the first few lots of a queue you were deep inside.

Worse, the cases where the queue does reach you are not a random sample. Resting orders get filled most reliably when price is about to go through them. A backtest that fills every touch gets every winner the live strategy misses and none of the losers it is missing them for.

This part covers what we assume about fills, why, and what each assumption has cost us.

Simulated bars of average P&L per filled buy limit by fill rule: +0.03 ticks on touch with 84% filled, falling to −3.98 ticks with 69% filled when price must trade 4 ticks through

Simulated: 40,000 buy limits 4 ticks under a ±1-tick random walk with no edge, 8-tick stop and target, no costs. The stricter the fill rule, the fewer touches fill, and the ones that do are worse trades: +0.03 ticks on touch, −0.93 one tick through, −3.98 four ticks through.

Three fill models for a resting limit

Fill on touch. The bar’s low reaches your buy limit, you are filled at the limit. Easiest to code, most optimistic. It assumes you were first in the queue.

Fill on trade-through. You are filled only if price trades at least one tick beyond your limit. If it went through, everyone at your price was filled, including you. Conservative and simple.

Queue simulation. Estimate your place in the queue from the size resting at that price when the order arrived, then fill only when enough opposing volume has traded at your price to reach you. Needs order-book data and still needs assumptions about cancellations ahead of you.

For most retail research, trade-through is the right default. It loses some fills that would have happened, which makes the backtest slightly pessimistic, and pessimism is the direction you want to be wrong in.

Adverse selection, measured

The intuition: price touches your buy limit and immediately rallies. If you were deep in the queue, you missed it. Price touches your buy limit and keeps falling. Everyone at that price is filled, you included, and the trade starts as a loser. The fills you get are a biased sample of the touches.

Two measurements from our own work.

Random entries on ES. In our corrected ES trend-pullback test we ran two controls through the same chronological fill engine: random entries at market, and random entries with a resting limit a quarter of an ATR into the dip. Same random signal, same exits, same costs. At market they lost $26.27 a trade. With the resting limit they lost $31.17. The limit bought a “better price” and a worse trade. The full table is in that article.

A maker simulation on NQ. For order-book imbalance on NQ we built a passive-entry simulator using real trade flow: an order’s queue position equal to the size resting ahead of it, filled only when enough opposing aggressive volume traded through that price. The fill rate was 43–53%, and the trades that did fill won 37–41% of the time. The simulator missed precisely the trades that would have worked, because price left without trading through.

How much the assumption is worth

The cleanest number we have comes from a VWAP limit scalp on NQ, tested tick by tick. With realistic fills it won 34.5% of trades across all VWAP touches and lost about $710k. We then gave it a fill model nobody could achieve: filled on any touch, targets filled without price trading through them, effectively a permanent first place in every queue. The win rate rose to 40.7% and it still lost $476,583. The Rother VWAP test shows both.

Dot plot of win rates for an NQ VWAP limit scalp under four fill models, 34.4% to 40.7%, against a 51.7% break-even and a claimed 80%; every version loses money

First touch only won 34.4%; an oracle that knew each day’s direction won 36.3% and still lost $5,315. Break-even was 51.7%.

That bound is a useful habit. If a strategy loses even with fills it could never get, no execution improvement will rescue it. If it only wins with those fills, it has no edge, only an assumption.

Gaps through a level: entries and stops

Stop orders and breakout entries have the opposite problem from limits. They will be filled, but not at the level when the market jumps past it.

A breakout that triggers on the open of a session that gaps through the level is filled at the open or worse. A protective stop that the market gaps through is filled at the first available price beyond it. Backtests that fill both at the level book profits that never existed.

Three examples from our own records:

  • ES narrow-range breakout. Filled at the level, $442.60 a trade; filled at the worse of the level and the next open, $116.11. $169,125 of the original result was overnight gaps. NR7 test.
  • NQ narrow-range breakout. A sleeve on our live board had been validated with entries booked at the level after seventeen untested overnight hours: +$447k at t = 7.5. Filled at max(level, open), −$70k. It was retired.
  • A live paper record. One of our live agents booked breakout entries at the level, including on mornings when the first tick of the session was already far beyond it. Rebuilt from the archived ticks, its paper record went from +$61,266 to +$19,873; single gap entries had been booked up to 470.75 points better than any price that traded.

The rule we apply in every engine and every live agent:

OrderFill price
Long entry on a triggermax(level, first available price)
Short entry on a triggermin(level, first available price)
Long protective stopmin(stop, first available price)
Short protective stopmax(stop, first available price)
Profit target (resting limit)the limit, never better

Targets are the one case not to clamp. A resting limit fills at its price or better; booking it worse than the limit would make the record artificially pessimistic.

The fill-agnostic check

For any strategy that enters with resting limits, we run one extra version: enter at market at the close of the bar that touches the level. No limit advantage, no queue, no adverse-selection modelling. If the edge survives that, it does not live in the fill assumption.

Two cautions from our own mistakes:

  • Do not use the trigger bar’s open as the market fill. For a level-trigger setup the open sits systematically on the wrong side of the level, because price had to travel through the level during the bar. One of our first “hard” fill models did exactly that and printed a large negative Sharpe that was a built-in penalty, not a finding.
  • Do not stop a close fill out on the same bar. A position entered at the close cannot be stopped by that bar’s low, which happened earlier. A placebo of ours that did this showed a fake loss of over a million dollars. Part 5 covers the engine rules.

The passive-versus-aggressive pincer

Any strategy that lives on small edges faces two bad options. Rest a limit and you capture a better price, but you are adversely selected and miss the best trades. Cross the spread and you get every fill, but you pay the spread on every one of them. A bar-based backtest cannot tell you which side wins; only order-flow data can.

Order-book imbalance on ES shows the extreme. After a strongly bid-heavy book the mid rises 0.3354 ticks over the next 30 seconds, about $4.19, while crossing costs $12.50, and the ES book is one tick wide most of the time. The signal is real on 73 of 76 sessions and belongs to whoever is already resting on the bid. A taker cannot collect it, and a late passive order is at the back of the queue it would need to be at the front of.

The practical consequence: if your edge per trade is small enough that the fill model decides its sign, you do not have a strategy yet. Part 8 puts numbers on “small enough”.

Checklist

  1. Default to trade-through fills for resting limits.
  2. Report what fraction of touches became fills, and the average trade of filled versus missed touches.
  3. Run a control with random entries through the same limit logic; compare with random entries at market.
  4. Fill triggers and stops at the worse of the level and the first available price.
  5. Fill targets at the limit, never better.
  6. Run the fill-agnostic check: market entry at the close of the touching bar.
  7. Compute a perfect-fill bound; if the strategy loses even there, stop.
  8. Measure the actual spread at your trading times before choosing passive or aggressive entries.

Fills decide whether you get the trade. Costs decide whether the trade is worth having. Part 8: Trading costs, slippage and the edge per trade a strategy needs.

Frequently asked questions

Does a limit order fill when price touches it?

Not necessarily. Orders at a price are filled in queue order, and a touch means at least one trade printed there, not that the queue reached you. Fill on touch assumes you were first in the queue, which overstates both the fill rate and the quality of the fills.

How should a backtest model limit order fills?

For most retail research, fill a resting limit only when price trades at least one tick through it. That loses some fills that would have happened and makes the backtest slightly pessimistic, which is the direction you want to be wrong in. A queue simulation is more precise but needs order-book data and assumptions about cancellations ahead of you.

What is adverse selection for limit orders?

The tendency for resting orders to be filled most often when the price is about to move against them. If price touches your buy limit and immediately rallies, the queue may never reach you; if it keeps falling, you are filled for sure. On ES, random entries with a resting limit lost $31.17 a trade against $26.27 for random entries at market.

How much does the fill assumption change a backtest?

Often more than the signal does. On a VWAP limit scalp on NQ, the realistic version won 34.5% of trades and lost about $710k across all touches; giving it perfect fills on every touch raised the win rate to 40.7% and it still lost $476,583. On an ES breakout, filling at the level instead of the next open added $169,125 of gap profit nobody could have taken.

What is a fill-agnostic check?

Re-run the strategy with a fill model that gives it no limit advantage: enter at market at the close of the bar that touches the level. If the edge survives that, it does not depend on optimistic limit fills. Do not use the trigger bar's open as the market fill for a level-trigger setup; the open sits systematically on the wrong side of the level.

Keep reading

How to Algo

Backtest vs Live Trading: Reconciling Every Trade

Why live trading drifts from the backtest: fills, latency, data gaps, rolls and code divergence. How to replay your live engine and reconcile trade by trade.

How to Algo

Tick Data vs Bars: What Resolution Your Algo Needs

Daily bars, minute bars, ticks or order-book depth? Match data resolution to the decision your algo makes, and see what a bar hides about stops and targets.