Automatic backtest: run a scripted strategy on cached bars
The Automatic backtest mode of the Replay screen runs a saved strategy script over weeks to years of cached bars with mandatory transaction costs, using the same conservative fill rules as the research backtester, and records the result in the Performance panel.
Senzoukria · Documentation · Updated September 2026
Where to find it
- Where
- Replay → Prepare → mode 'Automatic backtest' ('Months of bars — your strategy runs on its own')
- Defaults
- Period 1 month, granularity 15 minutes, point value $2, round-trip fee $1.24, slippage 1 tick
- Fill rules
- Entry at the next bar's open plus slippage, exits on wicks, stop wins on an ambiguous bar, fees on every trade
- Lookback
- A strategy sees the last 500 bars at each decision
What it does
Where the manual replay plays one day tick by tick, the automatic backtest runs a strategy written on the Scripting page over the bars stored in the local cache. The strategy exposes decide(bars, params, ctx, state) with bars newest first and returns an action: buy, sell or close, with an optional qty, stopTicks and targetTicks. The whole loop runs in the sandbox worker (the ofsandbox protocol, which carries its own CSP) in steps of 300 ms so the interface stays responsive; the same loop text also runs in a blob worker for tests and for the website, which guarantees identical results.
The panel first reads the cache for the chosen contract and granularity and reports coverage ('{n} sessions cached out of {n} requested'). Missing sessions can be downloaded from the broker (bars, or the footprint tick history when the strategy reads per-level imbalances), and a Databento ohlcv-1m file can be imported. Server bars carry OHLC, volume and delta but no footprint levels, and imported bars carry no delta at all.
Settings
| Setting | Default | What it changes |
|---|---|---|
| Strategy | 'Choose…' | A saved strategy from the Scripting page; 'Edit the strategy' opens the code, a modified draft runs without being saved, Ctrl+Enter re-runs. |
| Period | 1 month | 1 week, 1 month, 3 months, 6 months, 1 year, 2 years, 5 years (7 to 1,825 days). |
| Granularity | 15 minutes | 1 minute, 5 minutes, 15 minutes, 1 hour. Six months of 1-minute bars is about 250,000 bars and takes minutes per configuration. |
| Point value ($) | 2 (MNQ) | Dollar value of one full point per contract; minimum 0.01. |
| Round-trip fee per contract ($) | 1.24 | Subtracted from every trade; minimum 0. |
| Slippage (ticks) | 1 | Always penalises the entry: buys fill higher, sells fill lower; minimum 0. |
| Walk-forward | Off | Enables slices, training share, selection criterion and parameter axes (see the walk-forward page). |
| Run the backtest | — | Starts the run; 'Interrupt' aborts it. The result header reads 'Result · {n} bars'. |
Simulation rules
- A decision is taken on a closed bar and applied at the open of the next bar: no fill at a price that belonged to the past when the decision existed.
- Stops and targets are tested against the bar's high and low, not its close.
- When one bar touches both the stop and the target, the stop wins: without ticks the order is unknown, so the engine rules against you.
- Fees are applied to every trade; the costs hint reminds you that zero costs turn a losing strategy into a winning one as soon as it trades often.
- A reverse signal closes the current position first (reason 'reverse'); a close action flattens (reason 'flatten').
- MAE, MFE and the risk at entry (stop distance × qty × point value) are recorded per trade for the excursion and R-multiple charts.
- Script logs are kept up to 200 lines; a Python strategy runs through the interpreter installed from the Scripting page; C++ strategies cannot be backtested yet.
Limits or pitfalls
The result is recorded in the Performance panel as an 'auto' run with the days actually covered, and the list shows '{n} d of {req} asked' when coverage is under 90 % of the requested window. A backtest on partial coverage only covers that window, and the panel says so.
Historical bars are a broker entitlement: the panel distinguishes 'permission denied' (rp_code 13, bars not enabled on the account) from an archive that does not reach that far back. No orders are placed by a backtest; automated strategies only ever drive the simulated evaluation account.
Related pages
- Walk-forward analysis
- Backtest assistant (AI)
- Performance panel (past sessions)
- Futures backtesting guide
- Quant trading for beginners
This page in other languages
Frequently asked questions
- Why does the backtest fill at the next bar's open?
- The decision exists only once the bar is closed. Entering at a price of that same bar would use information you did not have yet, which is the first defect of naive backtesters.
- Can I set fees to zero?
- The field accepts 0, but the hint warns that a zero-cost backtest lies as soon as the strategy trades often. The default of $1.24 is an order of magnitude for a prop firm round trip.
- Why is there nothing cached for my contract?
- The cache fills when you open the contract in the chart at that granularity, or when you download the missing history from the backtest panel. A Databento ohlcv-1m file can also be imported.