Backtesting
Test trading strategies on historical data
Backtesting
Test your trading strategies on historical data to see how they would have performed.
What is Backtesting?
Backtesting simulates trades on historical price data to:
- Validate strategies before risking real money
- Optimize parameters like entry/exit rules
- Understand risk and potential drawdowns
- Build confidence in your approach
Running a Backtest
Step 1: Select Symbol(s)
- Go to Backtesting from the sidebar
- Enter one or more stock symbols
- Select date range for the test
Step 2: Choose Strategy
Select a pre-built strategy or create custom rules:
| Strategy | Description |
|---|---|
| Moving Average Crossover | Buy when fast MA crosses above slow MA |
| RSI Oversold/Overbought | Buy oversold, sell overbought |
| Breakout | Buy on new highs, sell on new lows |
| Mean Reversion | Buy dips, sell rallies |
| Custom | Define your own rules |
Step 3: Configure Parameters
Example for MA Crossover:
| Parameter | Default | Description |
|---|---|---|
| Fast MA Period | 10 | Short-term moving average |
| Slow MA Period | 50 | Long-term moving average |
| MA Type | SMA | Simple or Exponential |
| Position Size | 100% | % of capital per trade |
Step 4: Run Backtest
Click Run Backtest to execute simulation.
Understanding Results
Performance Summary
| Metric | Value | Benchmark |
|---|---|---|
| Total Return | +45.2% | +32.1% |
| Sharpe Ratio | 1.24 | 0.95 |
| Max Drawdown | -18.5% | -22.3% |
| Win Rate | 58% | N/A |
| Profit Factor | 1.65 | N/A |
| Total Trades | 47 | N/A |
Equity Curve
Chart showing cumulative returns over time: - Strategy line: Your backtest results - Benchmark line: Buy and hold comparison - Drawdown area: Shows peak-to-trough declines
Trade List
All simulated trades with details:
| Date | Side | Entry | Exit | P&L | Duration |
|---|---|---|---|---|---|
| 2024-01-15 | Long | $150.25 | $158.30 | +5.4% | 8 days |
| 2024-01-25 | Long | $155.00 | $148.50 | -4.2% | 5 days |
| ... | ... | ... | ... | ... | ... |
Strategy Types
Trend Following
Moving Average Crossover
BUY: Fast MA > Slow MA
SELL: Fast MA < Slow MA
Breakout
BUY: Price > 20-day high
SELL: Price < 20-day low
Mean Reversion
RSI Strategy
BUY: RSI < 30 (oversold)
SELL: RSI > 70 (overbought)
Bollinger Band Bounce
BUY: Price touches lower band
SELL: Price touches upper band
Momentum
Price Momentum
BUY: 12-month return > 0
SELL: 12-month return < 0
Custom Strategy Builder
Create your own rules:
Entry Conditions
Combine multiple conditions with AND/OR:
Entry when:
- RSI(14) < 30 AND
- Price > SMA(200) AND
- Volume > 1.5x Average
Exit Conditions
Define multiple exit triggers:
Exit when:
- RSI(14) > 70 OR
- Stop Loss: -5% OR
- Take Profit: +15% OR
- Max Hold: 30 days
Position Sizing
| Method | Description |
|---|---|
| Fixed % | Same % of capital each trade |
| Fixed Amount | Same $ amount each trade |
| Risk-Based | Size based on stop loss distance |
| Kelly Criterion | Optimal sizing based on edge |
Optimization
Parameter Optimization
Find the best parameters:
- Select parameters to optimize
- Set ranges (e.g., Fast MA: 5-20)
- Run optimization
- Review results heat map
Walk-Forward Analysis
More robust testing:
- In-sample: Optimize on first 70% of data
- Out-of-sample: Test on remaining 30%
- Roll forward: Repeat with moving windows
Risk Management in Backtests
Stop Loss Types
| Type | Description |
|---|---|
| Fixed % | Exit if price drops X% from entry |
| ATR-Based | Exit if price drops 2x ATR |
| Trailing | Stop moves up with price |
| Time-Based | Exit after N days regardless |
Position Limits
- Max position size
- Max concurrent positions
- Max sector exposure
Analyzing Results
What to Look For
| Good Signs | Warning Signs |
|---|---|
| Smooth equity curve | Jagged, volatile curve |
| Consistent wins | One big win skews results |
| Low drawdowns | Deep or long drawdowns |
| Many trades | Few trades (low confidence) |
| Beats benchmark | Underperforms buy & hold |
Common Pitfalls
| Pitfall | How to Avoid |
|---|---|
| Overfitting | Use out-of-sample testing |
| Look-ahead bias | Only use data available at time |
| Survivorship bias | Include delisted stocks |
| Ignoring costs | Include commissions, slippage |
Saving & Comparing
Save Backtest
- Click Save Results
- Name your backtest
- Access later from history
Compare Strategies
- Run multiple backtests
- Click Compare
- Side-by-side performance charts
From Backtest to Live
Validation Steps
- In-sample test: Initial development
- Out-of-sample test: Validation period
- Paper trading: Real-time simulation
- Small live test: Minimal capital
- Full deployment: If all tests pass
Reality Check
Backtests are optimistic because: - No slippage in simulation - Perfect fills assumed - No emotional interference - No market impact
Expect real performance to be 20-30% worse.