Skip to content

Backtesting Service ​

The backtesting service loads historical candles for a symbol and time range, compiles the script, and runs it over the full window. It returns candles, chart outputs, and, for strategy scripts, trade and performance reports.

What it does ​

  1. Load candles for [fromTime, toTime] from the configured candle source.
  2. Compile the script. Both indicator and strategy scripts are supported.
  3. Execute the script over the loaded window.
  4. Return candles, per-bar calculation results, and strategy analytics when applicable.

Unlike the validator, backtesting returns every bar in the calculation result, not just first-bar samples.

Typical use cases ​

  • Evaluate a strategy over a historical period.
  • Produce equity curves, trade lists, and performance summaries.
  • Render full-window indicator outputs alongside candle data.
  • Compare strategy return against buy-and-hold.

Script types ​

Both indicator and strategy scripts are supported. Strategy scripts must declare strategy() in the init section. See the Strategy reference for order simulation semantics.

Strategy response extras ​

When the script is a strategy, the response may include:

FieldDescription
strategyTradeReportClosed and open trades with PnL, drawdown, and signal names
strategyFillReportIndividual entry and exit fills per bar
strategyOrderReportResting orders and how each ended, plus any market order the account could not fund
strategyAnalyticsEquity series, performance summary, Sharpe/Sortino ratios, and related metrics

Indicator-only scripts omit these fields but still return calculationResult with per-bar output, spline, shape, backgroundColor, and barColor channels.

Request constraints ​

  • lang must be dxscript-js.
  • fromTime and toTime are required; fromTime must be before or equal to toTime.
  • symbol must be a valid dxFeed candle symbol (e.g. AAPL{=d} for daily candles).

On candle fetch failure, the response contains an error and an empty candle list. On script failure after candles are loaded, candles are still returned alongside the error.

API ​

See Backtest RPC for the HTTP endpoint, request body, and response schema. Strategy scripts use the strategy() language API; backtest responses include strategyTradeReport, strategyFillReport, strategyOrderReport, and strategyAnalytics defined there.