rungfolio

Gap fills

sim.gap-fill

What it does

If the session opens beyond an order's limit, the order fills at the opening price. The fill price is the open, not the limit. A rung's sell that starts working with the price already beyond its limit fills at the open too. At any other time, a limit order fills only at its limit.

How it works

What "beyond" means depends on the side of the order:

  • For a buy, the bar opens below the buy limit. The order fills at the open, which is lower than the limit.
  • For a sell, the bar opens above the sell limit. The order fills at the open, which is higher than the limit.

A bar that opens exactly at the limit isn't a gap. Like any bar that doesn't open beyond the limit, it comes under the trade-through rule.

An order can fill at the open only in the first bar it works in:

  • Most orders are working before the session opens: the rungs' buys, and the sells of lots bought on earlier days. Their first bar is the session's first one in regular hours, even when it starts after 9:30. The price jumps there most often, after news overnight.
  • A rung's sell is the second half of an OTO order, so it starts working once its buy fills. Its first bar is the one after its buy's.

In every later bar, the trade-through rule applies, even when the bar opens beyond the limit. The order fills at its limit if the price trades at least one tick past it, and the open counts as a trade. If the price goes less than a tick past the limit, the order doesn't fill.

When the session's first bar opens below several buy limits at once, each of those buys fills at the same open, as long as the cash covers it.

A buy that fills below its limit keeps its rung's usual sell, which is worked out from the buy limit, not from the fill (the sell target). So its sell sits more than the target above what it paid, by as much as the open was below the limit.

A re-armed rung whose buy limit is at or above the last close fills this way if the next session's first bar opens below its limit.

Examples

This session opens below rung 2's buy limit, so rung 2's buy fills at the open. The same bar trades down through rung 3's lower limit without opening below it, so rung 3's buy fills at its own limit, by the trade-through rule.

Worked example: the 1-minute bar at 9:30 am
BarOpenHighLowCloseFills
Working
Rung 2: Buy 6 TNA @ 81.95 → sell @ 84.41 · GTC OTO
Rung 3: Buy 6 TNA @ 81.75 → sell @ 84.21 · GTC OTO
9:30 am81.8081.9081.7081.85

Rung 2 bought 6 shares at 81.80. The price opened at 81.80, past the 81.95 limit, so the order filled at the open. Rule: sim.gap-fill

Rung 3 bought 6 shares at 81.75. The 81.75 buy filled because the price traded through it, down to 81.70. Rule: sim.fill-model

Cash$50,000.00 before the first bar, $49,018.70 after the last.

Here the price doesn't trade from 9:31 to 9:44, so there are no bars for those minutes. The 9:45 bar opens below rung 2's buy limit, but it isn't the session's first bar. So the buy fills at its limit, by the trade-through rule, not at the lower open.

Worked example: 1-minute bars from 9:30 am to 9:45 am
BarOpenHighLowCloseFills
Working
Rung 2: Buy 6 TNA @ 81.95 → sell @ 84.41 · GTC OTO
Rung 3: Buy 6 TNA @ 81.75 → sell @ 84.21 · GTC OTO
9:30 am82.1082.1282.0082.05Nothing filled.
9:45 am81.9081.9681.8881.93

Rung 2 bought 6 shares at 81.95. The 81.95 buy filled because the price traded through it, down to 81.88. Rule: sim.fill-model

Cash$50,000.00 before the first bar, $49,508.30 after the last.

This rung's sell sits much closer to its buy than the TNA template's 3% target would put it, close enough for the price to pass it within a minute. The 9:30 bar fills the buy. The sell starts working in the 9:31 bar, which opens above the sell's limit, so the sell fills at that open.

Worked example: 1-minute bars from 9:30 am to 9:31 am, with 1 working buy
BarOpenHighLowCloseFills
Working
Rung 2: Buy 6 TNA @ 81.95 → sell @ 82.20 · GTC OTO
9:30 am82.0082.1081.9082.05

Rung 2 bought 6 shares at 81.95. The 81.95 buy filled because the price traded through it, down to 81.90. Rule: sim.fill-model

9:31 am82.2582.3082.2282.28

Rung 2 sold 6 shares at 82.25. The price opened at 82.25, past the 82.20 limit, so the order filled at the open. Rule: sim.gap-fill

Cash$50,000.00 before the first bar, $50,001.80 after the last.

Why

Each session starts with an opening auction. It matches the orders waiting from before the open at one price, the open. A buy limit above that price buys at the open, and a sell limit below it sells at the open. Only the opening auction fills a waiting order at a better price than its limit.

Later in the session, a waiting limit order is already on the exchange's order book. When the price moves through it, the order fills at its own limit, however fast the move. So a later bar that opens past the limit fills the order at the limit, not at the open. Filling it at the open would make simulated results look better than real ones.

A rung's sell is a new order when its buy fills. If the price is already past its limit then, the sell trades at once, at the market price. A bar doesn't record when its prices happened, so the simulator uses the next bar's open.

In the app

A gap fill's "why?" names the open it filled at and the limit it passed.

Educational software, not investment advice.