Strategies

Fill Simulation

How the backtester decides when and at what price orders fill, how intrabar ordering questions are resolved with finer data, and how precision is reported.

Since engine 3.0.61; verified against engine 3.0.61. Every example on this page is an executed probe against that build.

The execution model

Orders are processed at each new confirmed bar in a fixed sequence:

  1. Protective exits of the open position (stop, limit, trail) are evaluated against the bar's range under the fill model.
  2. Pending signal exits from close and closeAll, in insertion order.
  3. Pending entries, in insertion order: market orders at the open, resting limit and stop orders if touched.
  4. Orders your script places during this bar join the queue for the next bar.

Fill prices follow bar mechanics:

  • Market fills execute at the next bar's open, slippage-adjusted.
  • Limit fills execute when the bar trades through the level (long entry: low <= limit), at the better of open and limit, with no slippage: a limit price is a bound by definition.
  • Stop fills mirror the touch rule and are slippage-adjusted, because stops cross the market.
  • Trailing stops activate when favorable excursion reaches trailPoints, then ratchet with new extremes and fill under stop rules with exitReason="trail".

Equity is recorded on every bar (cash plus the open position marked at that bar's close, minus fees paid), so drawdown and exposure account for flat periods too.

Intrabar ordering and fill models

A single OHLC bar tells you the range it traded, not the path it took. When both a protective stop and a profit limit sit inside one bar's range, the bar alone cannot say which traded first. The engine handles this class of question in three layers:

  1. Certainty first. A leg already marketable at the open fills at the open. Decisions that are certain at chart level never involve any assumption.
  2. Finer data second. When the platform holds finer-interval bars for that epoch, the engine walks them in time order and lets the actual path settle the question (see below).
  3. Declared assumption last. Only when no finer data covers the bar does the declared fillModel decide:
    • "pessimistic" (default): the stop is assumed to have filled first. The decision is counted in ambiguousFillCount and the trade is flagged.
    • "pathHeuristic": the TradingView-style path assumption (the open moves toward the nearer of high and low first). Natural path resolutions are not counted; only exact distance ties fall back to the pessimistic rule and count.

Both models are fully deterministic.

Sub-bar resolution

Backtests load a ladder of finer-interval bars over the replay window, subject to what the platform retains per lane (roughly: 1m for recent days, then 5m, 15m, and 1h reaching back years). Every ordering question that falls inside covered epochs is resolved by walking those finer bars with the exact same per-bar rules (touch, gap-through at opens, limit legs unslipped, stops slippage-adjusted). The first leg to trigger wins, at the triggering sub-bar's price.

Two properties keep this honest:

  • Uncontested fills are byte-identical with and without finer data. The walk resolves ordering, it never changes the price of a fill that was already certain.
  • If a single finest-lane bar still contains both levels, that residual question is settled by the declared fillModel and counted, exactly as a chart bar would be.

Reading the precision report

The Strategy Tester's run-details popover reports what the simulation actually did:

  • Fill precision: exact. The run posed no intrabar ordering questions at all.
  • Fill precision: verified on 1m + 5m data. Every contested fill was settled by walking finer bars.
  • Fill precision: N of M contested fills verified. Partial coverage: the rest were settled by the fill model over epochs with no finer data.
  • Fill precision: bar resolution. No finer data was available; the fill model settled everything.

The same popover reports the compute time and, for slippageModel="bookEstimate" runs, the slippage disclosure.

Choosing an interval to trust

Cross-interval agreement has one structural limit worth understanding: brackets arm on the bar after the entry fills. On a 1-hour chart that protection gap is an hour of price movement; on a 1-minute chart it is a minute. A strategy whose stops are tight relative to its chart interval will genuinely behave differently at finer intervals, and no fill simulator can reconcile that, because the strategies are seeing different information. Practical guidance:

  • Backtest at the interval you intend to run the strategy on.
  • Keep stops and targets wide relative to the chart interval's typical bar range, or move to a finer chart.
  • Treat the precision line as part of the result. A verified run at bar resolution over deep history and a fully walked run over recent months are both useful, but they are not the same experiment.