Why Your Backtest Order Can't Fill on the Same Bar

Your order can't fill on the bar that triggered it. Here is the one-line rule that stops lookahead in Kestrel's simulated venue.

Introduction

Not on the bar you saw

Your order cannot fill on the bar you saw. Not ever.

  • Decision bar is off limits

A bar finishes before you act

Why? Because a bar is only complete once it closes. Its close is information your strategy used to decide.

  • Close is known only at the end

Same-bar fills are lookahead

Fill that order inside the same bar, and your backtest quietly trades on the future. That is lookahead.

  • Trading on the future

The one-line condition

Kestrel's simulated venue blocks it with a single eligibility condition on every working order.

  • bar.start > lastBarStartAtSubmit
  • bar.start >= createdAt

Two clauses, two guards

The first clause says the bar must start after the last bar seen at submission. The second says it must start after the order was created, plus optional latency.

  • After the last seen bar
  • After creation plus latency

Earliest fill: bar t plus one

So an order decided on bar t can only fill on bar t plus one.

  • Decision bar crossed out

Worked example

And it fills at that bar's open, plus slippage. Take a two basis point market buy at an open of twenty-five hundred.

  • Open 2500.00
  • Slippage 2 bps

Round up to the tick

Two basis points adds fifty paise. The price lands on a tick, so rounding up to the zero point zero five tick gives twenty-five hundred and fifty paise.

  • Buys round up
  • Fill: Rs 2500.50

No peeking

One condition, no peeking. Follow for the next piece of Kestrel's fill rules.

  • Follow for more Kestrel