DocsRun Modes

Backtest

A backtest replays your strategy against historical candles to simulate how it would have traded. It is the fastest way to see whether a strategy idea has merit.

How It Works

  1. Candles are fetched for the chosen symbol, interval, and date range
  2. Your strategy's define(), init(), and onBar() functions are called in sequence
  3. The trading engine simulates order fills, portfolio tracking, and fee deduction
  4. Results include every trade, performance stats, and an equity curve

Inputs

SettingDescription
SymbolTrading pair (e.g. BTCUSDT)
IntervalCandle timeframe (1h, 4h, 1d, etc.)
Date rangeStart and end dates, or candle index range
StrategyYour QSL strategy
ParametersValues for each parameter defined in define()
AllocationStarting capital (default 10,000 USDT)
Trading modeLONG_ONLY, SHORT_ONLY, or BIDIRECTIONAL
Fee %Per-trade fee (default 0.1%)

Trading Modes

ModeDescription
LONG_ONLYOnly long (buy) positions. This is the default.
SHORT_ONLYOnly short (sell) positions. Automatically uses MIXED portfolio.
BIDIRECTIONALBoth long and short positions allowed.

Output

A completed backtest returns:

  • Trades — every entry and exit with prices, dates, P&L, and portfolio snapshots
  • Statistics — trade count, win rate, total return, Sharpe ratio, max drawdown, profit factor, Calmar ratio
  • Signals — the raw signal array from your strategy
  • Metadata — symbol, interval, candle count, fee rate, and whether data was truncated

Candle Limits

Very large date ranges are automatically capped to prevent excessive memory usage. If your range exceeds the system limit (~50,000 candles), only the most recent candles are used and a warning is included in the metadata.

Tips

  • Start with a single instrument and a wide date range to see overall behaviour
  • Use the default parameters first, then move to Optimization to tune them
  • Compare LONG_ONLY vs BIDIRECTIONAL to see if short signals add value
  • Check the max drawdown — a high return with extreme drawdown is risky
backtestrunsimulationtradesequitystatssingle run