Docs menu

Look-ahead protection

Look-ahead is a backtest that uses information which did not exist yet at the moment of the decision. The engine is built so that a strategy only sees the past. Each guarantee below is audited, and the audit lists the regression test that pins it.

Orders and fills

  • On 1s data, each source bar's fills are applied before the trading-bar close reaches the strategy. An order placed at a bar's close is not resting while that bar sweeps, so it can only fill against bars that arrive after the decision.
  • A pinned example: a bar prints a high of 105, then a buy stop is placed at 103. The stop does not fill against the 105 that already printed. It fills only on a later bar that crosses 103.
  • An order fills inside a bar only if it existed before that bar.
  • Slippage reads the spread of the bar the fill happens in. Market impact reads only bars before the fill bar.

An order placed at a bar's close becomes fillable one source bar late, so up to one second on 1s data. That delay is pessimistic, never optimistic.

What a strategy reads

  • At a bar close, offset 1 is the bar that just closed and is complete. Offset 0 is the forming next bar, which holds only the present second.
  • The daily series and up to three extra timeframes declared with AddTimeframe follow the same rule. Offset 0 is the forming period, and offset 1 and beyond are completed periods. On 1m data the forming bar starts with only the incoming minute's open.
  • A strategy written with the Strategy Kit is refused when it is defined if it reads index 0 of a closed series, unless it declares Style(intrabar: true). An unseen index 0 read at run time returns NaN and is counted.

Filters and selection

  • The volatility regime filter uses trailing completed bars only. The regime at a bar is computed from returns up to the bar before it.
  • The session window and weekday filter compare the stamp of the new bar's open against fixed clock times, and read no bar data beyond that stamp.
  • Daily selection uses fully closed daily bars only. The coins traded on day T are chosen from the data at the end of day T-1.
  • The selector preview reads only the days up to the previewed day.

Related: Fills and slippage and Latency.