Backtesting Strategies
Detailed content
Backtesting
Evaluate rules on historical data with realistic assumptions.
Process
- Define precise entry/exit/filters and management rules.
- Use clean data; include fees/slippage; avoid peeking bias.
- Segment by regimes; compute win rate, avg R, max drawdown, Sharpe.
- Validate out‑of‑sample then forward‑test on paper before live.
Detailed Backtest Example: RSI Divergence Strategy
Strategy rules:
- Entry: Hidden bullish divergence on H1 when HTF (D1) is uptrend, RSI < 45, price touches 20‑EMA
- Stop: 25 pips below entry (or below prior swing low)
- Target: 2R (50 pips) for 50%, trail remainder with 20‑EMA
- Filter: Only trade London/New York sessions, avoid 30 min before major news
Backtest Results (EURUSD, Jan 2023–Dec 2023)
- Total trades: 87
- Wins: 48 (55.2%)
- Losses: 39 (44.8%)
- Avg win: +2.3R
- Avg loss: −1R
- Expectancy: (0.552 × 2.3R) − (0.448 × 1R) = 1.27R − 0.448R = +0.822R per trade
- Total return: +71.5R over 87 trades
- Max drawdown: −8.5R (consecutive 11 losses)
- Sharpe ratio: 1.42
- Largest win: +5.2R
- Largest loss: −1.2R (slippage)
Out‑of‑Sample Validation (Jan 2024–Jun 2024)
- Total trades: 42
- Expectancy: +0.76R per trade (slightly lower but acceptable)
- Win rate: 52.4% (similar to in‑sample)
- Conclusion: Strategy is robust; proceed to forward testing
Forward Test (Paper Trading, Jul 2024–Sep 2024)
- Total trades: 28
- Real expectancy: +0.68R (includes real slippage/spreads)
- Note: Slippage reduced expectancy by ~0.1R (expected)
- Decision: Go live with 0.5% risk per trade initially
Common Backtesting Mistakes
- Overfitting: Optimizing 10 parameters → 95% win rate (unrealistic)
- Solution: Limit to 2–3 parameters, test on multiple pairs/timeframes
- Ignoring fees: Backtest shows +100R, reality +85R after commissions
- Solution: Add 0.1% commission + 1 pip slippage per trade
- Survivorship bias: Testing only current liquid pairs
- Solution: Include pairs that were delisted/merged