Type/to search
Getting Started
Platform Basics
Writing Strategies
Development Tools
Backtesting System
Overview and Starting a Backtest
Backtest Modes and Order Matching
Backtest Configuration and Saving
Supported Languages and Exchanges
Reading Backtest Results
Parameter Optimization
Custom Data Source
Local Backtesting Engine
Backtest Page Shortcuts
Advanced Topics
Data and Research
Extended API Interface

A backtest drives the strategy code with the platform's historical market data: the backtest engine keeps a virtual clock and one simulated account per exchange object, and answers every market, order and account call from history. A backtest only shows how the strategy would have behaved on past data; the past does not represent the future, so read backtest results with caution.

Starting a backtest

  • Website: open the strategy editor, switch to the "Backtest" tab, set the backtest configuration and strategy parameters, then click "Start Backtest" (keyboard shortcuts: see Backtest Page Shortcuts). The configuration can be saved into the strategy source, see Backtest Configuration and Saving.
  • AI assistant: start a backtest with the MCP tool run_backtest and read the result with get_backtest, see AI Integration. Backtests started through MCP always use the simulated-tick mode.
  • Your own machine: use the open-source local backtest engine, see Local Backtesting Engine.

Configuration items

ItemDescription
Time rangeStart and end time of the backtest.
K-line periodThe K-line period that GetRecords() returns by default.
Base K-line periodThe K-line period from which ticks are generated in simulated-tick mode.
ModeSimulated tick or real tick, see Backtest Modes and Order Matching.
Exchange, trading pairEach exchange object has its own simulated account; pairs are written like BTC_USDT.
Initial fundsInitial balances of the quote currency (e.g. USDT) and the base currency (e.g. BTC).
FeesMaker and taker rates in percent.
SlippageNumber of price ticks (minimum price increments) added outside the simulated best bid and ask; default 0.
Network delayMilliseconds the virtual clock advances on every exchange call; default 200.
Depth levels, amount per levelNumber of levels GetDepth() returns (1-20) and the amount on each simulated level.
Max K-line barsUpper limit of history bars returned by the first GetRecords() call (100-5000, default 300).
Log limitsUpper limits on kept runtime logs, profit logs and chart data points.
Data sourceThe platform's historical data by default, or a Custom Data Source.

Further details:

  • The smaller the base K-line period, the closer the generated ticks are to the real market and the slower the backtest; strategy K-lines are built from base K-lines, so the K-line period cannot be shorter than the base period.
  • On cryptocurrency futures exchanges the contract defaults to swap (perpetual); to use another contract, call exchange.SetContractType() in the strategy first.
  • Coin-margined contracts use the base currency as margin, so set the base-currency balance.
  • Fees default to the exchange market's configuration. A limit order that fills immediately when placed pays the taker rate; one that rests in the book and is filled later pays the maker rate.
  • Slippage applies only in simulated-tick mode; real-tick mode uses the replayed real order book, and there the depth levels are the real depth requested from the data source.

Fault-tolerance test

The backtest page also offers a "fault-tolerance test": exchange calls fail with a given probability (0.5 by default), and the first call of each kind always fails; each failure is logged as the error FaultTolerant Test. Use it to check how the strategy handles failed calls, e.g. whether it retries with _C().

What the strategy sees in a backtest

  • IsVirtual() returns true; logic that must not run in a backtest can be skipped based on it, see IsVirtual.
  • Time is virtual: Unix(), _D() and similar functions read the backtest clock, and Sleep() advances it. When the clock passes the end time, the engine throws an EOF exception and the backtest ends; JavaScript and Python strategies do not call onexit() in that case (see onexit() for how to handle this), while Rust strategies call onexit() automatically.
  • In a backtest GetCommand() receives no interactive commands, onerror() is not supported, and network request functions are restricted.