Run backtest
run_backtestBacktest a trading strategy over historical data to evaluate performance and set a baseline for optimization.
Instructions
Backtest a strategy over a historical window and wait up to 180s for it to finish. Use this after create_strategy or edit_strategy to measure real performance, and before optimize_strategy to establish a baseline. Parameters: strategyId (UUID, required); startDate and endDate (YYYY-MM-DD, optional, must be real past dates with endDate after startDate and at least 7 days between them - default is the last 365 days); timeframe: one of 1m, 5m, 15m, 1h, 1d - defaults to the strategy's native timeframe, fetched automatically; initialCapital in USD (number 100 to 100000000, default 50000). Returns metrics (totalTrades, totalOrders, totalReturnPct, sharpeRatio, maxDrawdownPct, winRate) plus up to 8 diagnostic messages verbatim - read these, they carry gate pass-rate evidence explaining WHY the strategy did or did not trade - and an explicit note when 0 trades closed but orders were opened (the strategy entered and is still holding, which is not the same as a dead strategy). A warning is added when a 1d strategy is tested over fewer than 300 days, since that is too few bars to judge it. On timeout the error names the backtest id, which get_job_status accepts as a fallback.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | No | Window end, YYYY-MM-DD. Must be a real calendar date no later than today, after startDate, and at least 7 days from it. Defaults to today. | |
| startDate | No | Window start, YYYY-MM-DD (2000-01-01 or later). Defaults to 365 days before endDate. | |
| timeframe | No | Bar timeframe: one of 1m, 5m, 15m, 1h, 1d (lowercase). Defaults to the strategy's native timeframe, fetched automatically. | |
| strategyId | Yes | Strategy UUID. Find it with list_strategies (it is also returned by create_strategy). Not a strategy name. | |
| initialCapital | No | Starting cash for the backtest. Number between 100 and 100000000; defaults to 50000. |