Backtesting
Test your agent against historical market data and see detailed performance metrics, charts, and trade breakdowns.
Running a backtest
From the agent editor, click the "Backtest" button to open the configuration dialog. Choose your settings and click "Run".
Configuration options
| Setting | Default | Description |
|---|---|---|
| Dataset | Sample BTC-USD | Historical data to backtest against. See Datasets. |
| Initial Capital | $10,000 | Starting cash for the simulation. |
| Fee Rate | 0.1% | Trading fee applied on both entry and exit. |
| Position Size | 95% | Percentage of available cash used per trade. |
| Risk-Free Rate | 2% | Annual rate used for Sharpe/Sortino calculations. |
| Slippage | 5 bps | Simulated price slippage in basis points. |
Execution modes
- Dry Run -- Quick test that runs the agent and shows logs, trades, and output without full metrics.
- Full Backtest -- Complete simulation with portfolio tracking, position sizing, fees, slippage, and all performance metrics.
Engine behavior
- Position sizing -- Calculated as
(cash * position_size) / (fill_price * (1 + fee_rate)). The agent's quantity field is ignored in backtest mode. - Long and short -- Both long and short positions are supported. Use "buy"/"sell" for longs, "short"/"cover" for shorts.
- One position at a time -- Buy signals are ignored if already in a position. Sell signals are ignored if not in a position.
- Fees -- Applied on both entry and exit as
price * quantity * fee_rate. - Slippage -- Buys/covers fill at
price * (1 + bps/10000), sells/shorts fill atprice * (1 - bps/10000). - Stop loss / Take profit -- Checked each bar BEFORE
on_baris called. Stop loss is checked first (conservative). - Force close -- Any open position is automatically closed at the last bar's price when data ends.
Performance metrics
The following metrics are computed automatically after each backtest:
Total Return
Percentage gain/loss on initial capital
Sharpe Ratio
Risk-adjusted return (annualized)
Sortino Ratio
Like Sharpe, but only penalizes downside volatility
Max Drawdown
Largest peak-to-trough decline
Win Rate
Percentage of profitable trades
Profit Factor
Gross profit / gross loss
Expectancy
Average profit per trade ($/trade)
Avg Win / Avg Loss
Mean profit of winning vs losing trades
Max Consecutive Wins
Longest winning streak
Max Consecutive Losses
Longest losing streak
Total Trades
Number of completed round-trip trades
Final Equity
Portfolio value at end of simulation
Total Fees
Sum of all fees paid during simulation
Charts and visualization
- Candlestick chart -- Full OHLCV price chart with trade entry/exit markers (colored points showing buy/sell/short/cover). Overlay up to 5 technical indicators. Supports fullscreen mode.
- Equity curve -- Portfolio value over time with drawdown shading.
- Drawdown chart -- Peak-to-trough decline visualization over time.
- PnL distribution -- Histogram showing the distribution of trade profits and losses.
- Trade table -- Sortable list of all trades with entry/exit times, prices, quantities, P&L, and exit reason.
Iterating on results
After a backtest completes, you have several ways to iterate:
- Re-run -- Click "Re-run Backtest" to run again with different configuration (dataset, capital, fees, etc.)
- Edit code -- The agent code is visible and editable directly from the backtest results page.
- Fork agent -- Create a copy of the agent to try variations without modifying the original.
- AI chat -- Use the AI Assistant to discuss results, get improvement suggestions, and debug strategy logic.