How to Backtest a Trading Strategy — The Right Way
Backtesting is the process of testing a trading strategy against historical data to see how it would have performed. Done right, it gives you confidence before risking real money. Done wrong, it gives you false confidence — which is worse than no testing at all.
Why Backtesting Matters
Would you invest in a business without seeing its financial history? Trading is the same. A backtest is your strategy's financial history — simulated, but based on real market data.
- Validates your edge — Does the strategy actually make money over time?
- Reveals weaknesses — How does it perform in trending vs choppy markets?
- Sets expectations — What's the max drawdown? How many consecutive losses?
- Builds confidence — Easier to trust a system you've seen work over 10,000 trades
Step-by-Step Backtesting Process
Write down exact entry and exit rules. "Buy when the trend looks good" is not a rule. "Buy when the 6-period SMA of the open crosses above the 20-period SMA" is a rule.
Your rules should be 100% objective — a computer should be able to follow them without interpretation.
Get historical price data for the market you want to trade. More data is better — at least 2 years, ideally 5+. Make sure the data includes different market regimes: trending, ranging, volatile, and calm.
Data sources: TradingView, ThinkorSwim, Yahoo Finance, Quandl, or your broker's platform.
This is critical. Divide your data into two periods:
- In-sample (70%) — Use this to develop and optimize your strategy
- Out-of-sample (30%) — Use this to validate. Never optimize on this data.
If your strategy works on both periods, it's more likely to work in live trading.
Apply your rules to the in-sample data. Record every trade: entry, exit, P&L, duration. Calculate key metrics: win rate, profit factor, max drawdown, expectancy.
Run the exact same rules on the out-of-sample data without changing anything. If the results are similar to in-sample, your strategy is robust. If they fall apart, you've overfit.
Randomize the order of your trades 10,000 times. This shows you the range of possible outcomes — not just the one sequence that happened historically. Use the 95th percentile drawdown for position sizing.
Run the strategy in real-time on a demo account for at least 2-4 weeks. This catches issues that backtests miss: slippage, execution delays, and platform differences.
The #1 Backtesting Mistake: Curve Fitting
Curve fitting is when you optimize a strategy until it looks perfect on historical data — but it only works on that specific data. It's the most common and most dangerous mistake in algo trading.
Signs of curve fitting:
- Too many parameters — If your strategy has 10+ adjustable settings, it's probably overfit
- Perfect-looking equity curve — Real strategies have drawdowns. If yours doesn't, something is wrong.
- Fails out-of-sample — Works beautifully on training data, falls apart on new data
- Only works on one market — A robust edge should work across similar markets
- Optimized parameters are extreme — If the best result requires very specific settings, it's fragile
How to Avoid Curve Fitting
- Keep it simple — Fewer parameters = more robust. 2-3 rules is better than 10.
- Use out-of-sample testing — Always validate on data the optimizer never saw
- Test across markets — If it works on ES and NQ, it's more likely robust than if it only works on ES
- Prioritize profit factor over raw P&L — A strategy with 1.3 profit factor is more reliable than one with 3.0 that's overfit
- Accept imperfection — A slightly messy equity curve that's robust beats a perfect one that's overfit
Key Metrics to Evaluate
- Profit Factor — Gross profit / gross loss. Above 1.2 is good, above 1.5 is strong.
- Win Rate — Percentage of winning trades. 40-60% is typical for profitable systems.
- Max Drawdown — Largest peak-to-trough decline. This is what you'll live through emotionally.
- Expectancy — Average profit per trade. Must be positive.
- Trade Count — Need hundreds of trades minimum for statistical significance.
- Sharpe Ratio — Risk-adjusted return. Above 1.0 is good.
Backtesting Platforms
- TradingView — Pine Script, visual, easy to use. Good for beginners.
- ThinkorSwim — Built-in strategy tester. Good for futures.
- Python (backtrader, zipline) — Full flexibility, requires coding.
- QuantConnect — Cloud-based, institutional-grade.
- MetaTrader — Popular for forex. MT4/MT5 with MQL.
From Backtest to Live: What Changes
Your live results will be worse than your backtest. Always. Here's why:
- Slippage — You won't always get the exact price in the backtest
- Execution delay — Real orders take milliseconds, backtests are instant
- Platform differences — Different platforms calculate indicators differently
- Market impact — Your orders can move the market (less relevant for small accounts)
- Psychology — Watching real money drawdown feels different than backtested drawdown
Rule of thumb: Expect live results to be 20-40% worse than backtested results. If your backtest is barely profitable, your live trading will likely lose money.
See a Backtested Strategy Running Live
11,949 backtested trades across 4 futures markets. Same algorithms now running live with every trade logged.
View Live Results →7-day free trial · No credit card required
Trading involves substantial risk of loss. Past performance — backtested or live — is not indicative of future results. This is educational content, not financial advice.