Workspace / Research tools
Guide

Backtesting without look-ahead bias

A backtest can produce precise numbers from impossible trades. The key question is whether every decision used only information available at that moment, and whether the modeled order could have executed afterward. Separate those two checks before treating the equity curve as evidence about a strategy.

Explicit assumptionsFormula & methodology includedNo account required

A candle's timestamp is not necessarily its availability time

An hourly bar labeled 12:00 may summarize trading from 12:00 through 12:59:59. Its final close, high, low and volume are not known at 12:00. Binance's kline response documents separate open and close timestamps. Read the provider's convention before aligning indicators with orders.

QuantConnect's time-modeling documentation uses a time frontier and each data point's end time to control availability. The practical principle is simple: unfinished observations must not supply their eventual final values to an earlier decision. The same issue applies to news release times, revised economic data and funding rates that were not yet settled.

Model the signal first and the fill afterward

Imagine a moving-average rule that changes from flat to long after the 12:00 hourly bar closes. A simple bar-based implementation can form its signal from that completed bar and model a fill at the next bar's open. It must not buy at the previous bar's open using a close that happened almost an hour later.

For a numerical illustration, suppose the completed signal bar closes at 60,000 and the next available modeled open is 60,180. An assumed 5 basis points of adverse buy slippage produces a fill of 60,210.09, before the trading fee. Using 60,000 instead silently improves the modeled purchase. Even the next-open model is an approximation: actual latency and available liquidity may produce a different fill.

Do not infer an intrabar path that the data cannot show

A candle containing both a stop level and a profit target does not reveal which was reached first. Selecting whichever outcome helps the strategy injects favorable information into the result. Use finer data where available, or document a consistent conservative rule for ambiguous bars. A bar's low touching a buy limit also does not prove that your order received a fill.

Model entry and exit fees, spread or slippage, and position sizing in units that match the traded product. Perpetual strategies additionally need funding and margin behavior. Spot candles alone cannot establish the liquidation path of a leveraged perpetual account. Missing candles should be investigated or explicitly excluded rather than silently presented as continuous observations.

Test the assumptions as well as the strategy

Construct a small hand-checkable sequence where a signal appears only after a known bar closes. Confirm that no position exists earlier and that both entry and exit costs reach the cash ledger. Then append unrelated future candles: decisions already made in the earlier segment should not change. This helps expose accidental references to future rows.

Keep a later period aside while choosing rules, then evaluate the frozen rules on that period. Repeatedly changing parameters after inspecting that result turns it into another development sample. Compare against a relevant baseline using the same dates, initial capital and costs, and inspect drawdown, turnover and individual fills alongside total return. Passing these checks improves the integrity of the experiment; it does not establish future profitability.

Questions about this tool

Does executing at the next open remove every backtesting bias?

No. It addresses one timing mistake. Future-dependent data preparation, parameter selection, unavailable assets, unrealistic fills and omitted costs can still distort the result.

Is a profitable backtest enough to enable live trading?

It shows the outcome of a historical model under stated assumptions. Forward observation, paper execution and reconciliation of real fills are separate checks; none guarantees future returns.

Sources and further reading

QuantConnect: timeslices and the availability frontier ↗Binance Spot API: kline open and close timestamps ↗

Find a tool or explanation