General

Backtesting

Last Updated
Quick Definition

Backtesting — Backtesting is testing a trading strategy against historical price data to evaluate its potential performance before risking real capital.

Track Backtesting with PipJournal

Backtesting is testing a trading strategy against historical price data to evaluate whether it would have been profitable in the past, providing statistical validation before risking real capital.

Why Backtest?

Before you risk $10,000 of real money, backtesting lets you test 10,000 historical trades for free.

Benefits:

  1. Reveals true win rate: Not your gut feeling, but actual %
  2. Shows maximum drawdown: Worst case scenario in past data
  3. Calculates expectancy: Average profit/loss per trade
  4. Tests multiple market conditions: Trends, ranges, volatility
  5. Saves money: Discovers flaws before they cost real cash
  6. Builds confidence: Profitable backtest = you know the edge exists
  7. Finds extreme cases: Largest wins, largest losses, longest drawdowns

A trader with a profitable backtest sleeps better than one trading a gut feeling.

How to Backtest: Step by Step

Step 1: Define Your Strategy Rules

Write down exact entry, exit, and risk rules. No ambiguity.

Example: Breakout Strategy

  • Instrument: EURUSD, 4-hour chart only
  • Entry: Price breaks above the 20-period high (last 20 candles)
  • Exit 1: Profit target 50 pips
  • Exit 2: Stop loss 20 pips
  • Position size: 1 lot per trade
  • Filters: Only trade during London session (3 AM - 12 PM ET)

If you can’t write it down, you can’t backtest it objectively.

Step 2: Gather Historical Data

Get 2-5 years of price data for your instrument.

Data sources:

  • MetaTrader 4/5: Built-in history; download via Tools > Data
  • TradingView: Charts have historical data; export via API
  • Broker data: Most brokers provide historical CSV files
  • Paid data: HistData.com, Ninjatrader, Interactive Brokers

Data quality matters. Use minute or tick data for 1-hour to 4-hour strategies. Daily data for longer timeframes.

Step 3: Run the Backtest

Use a backtesting tool:

Code-based:

  • MetaTrader EA (Expert Advisor): Test algorithmic strategies
  • TradingView Pine Script: Write strategy, test visually
  • Python + backtrader: Custom strategies, full control

Manual:

  • Spreadsheet: Slow but teaches rules
  • TradingView: Visual replay mode; you execute manually

Step 4: Analyze the Results

After running 100+ trades, extract key metrics:

MetricHow to InterpretHealthy Range
Win Rate% of trades that hit profit target>40%
Average WinAvg pips on winning trades> $200
Average LossAvg pips on losing trades< $100
Expectancy(Win% × Avg Win) - (Loss% × Avg Loss)> 0 (profitable)
Profit FactorGross wins ÷ Gross losses> 1.5
DrawdownLargest peak-to-trough decline< 25%
ReturnTotal profit ÷ Starting capitalVaries by timeframe

Red flags:

  • Win rate <35%: Strategy needs work
  • Expectancy negative: Strategy loses money
  • Drawdown >30%: Position sizing too aggressive
  • Profit factor <1.2: Risk is high relative to reward

Real-World Backtest Example

Strategy: EMA Crossover (Simple but Effective)

  • Entry: EMA(9) crosses above EMA(21) on 4-hour chart = BUY
  • Exit: EMA(9) crosses below EMA(21) = SELL (exit)
  • Stop loss: 30 pips below entry
  • Position: 1 lot EURUSD

Backtest on EURUSD 4-hour, 2020-2025 (5 years):

  • Total trades: 87
  • Winning trades: 39
  • Losing trades: 48
  • Win rate: 44.8% ✓
  • Average win: 58 pips
  • Average loss: -26 pips
  • Expectancy: (44.8% × 58) - (55.2% × 26) = 26.0 - 14.4 = +11.6 pips/trade
  • Gross profit: 39 wins × 58 pips = 2,262 pips
  • Gross loss: 48 losses × 26 pips = 1,248 pips
  • Net profit: 2,262 - 1,248 = +1,014 pips = $10,140 profit
  • Max drawdown: -$1,850 (1.85%)
  • Profit factor: 2,262 ÷ 1,248 = 1.81

Verdict: This strategy is profitable. Positive expectancy, decent win rate, acceptable drawdown. Ready for live testing.

In-Sample vs. Out-of-Sample Testing

This is critical for avoiding curve-fitting.

In-sample: Test on data the strategy was optimized for. Out-of-sample: Test on data the strategy never saw.

Example:

  1. Optimize strategy on 2020-2022 data (in-sample) = 55% win rate
  2. Test same parameters on 2023-2025 data (out-of-sample) = 42% win rate

The out-of-sample result is more reliable because the strategy wasn’t tweaked to fit that data.

If out-of-sample results are significantly worse (20%+ drop in win rate), the strategy is curve-fit. It was optimized to past data, not the market.

Common Backtesting Mistakes

Mistake 1: Only testing the best market You backtest during a bull market and get 60% win rate. When you trade live in a bear market, it drops to 20%. Backtest across bull, bear, range-bound, and volatile conditions.

Mistake 2: Over-optimizing parameters You optimize EMA lengths from 5 to 100, find the perfect combination (EMA 17 × EMA 64) with 70% win rate. That’s curve-fitting. Test the strategy with standard parameters (EMA 9 × 21) on out-of-sample data.

Mistake 3: Ignoring slippage and commissions Backtest assumes perfect fills. Real trading: entry 2-3 pips worse, exit 2-3 pips worse. Subtract 4-6 pips from each trade. If your backtest profit disappears after slippage, the strategy is too thin to trade.

Mistake 4: Cherry-picking data You test 2020-2022 and the strategy works great. You ignore that 2022-2023 was the worst drawdown period. Test full years, not selective periods.

Mistake 5: Too few trades 20 trades isn’t a sample; it’s a coincidence. You need 100+ trades to know true win rate and drawdown. Test longer.

Mistake 6: Ignoring black swan events Backtests don’t show COVID crashes, central bank surprises, or wars. A strategy that lost 20 pips max in backtest might lose 200 in a black swan. Assume worst case is 2x worse than backtest.

Backtesting Tools Comparison

ToolProsConsBest For
MetaTraderEasy, built-in data, shows trades visuallyLimited optimization, slowerSimple strategies
TradingViewVisual replay, intuitive, browser-basedLimited backtesting featuresLearning
PythonFull control, customizable, accurateSteep learning curve, requires codingAdvanced traders
ExcelSimple, transparentSlow for large datasets, manualEducational

Key Backtesting Statistics

Expectancy (most important): Expected profit per trade = (Win% × Avg Win) - (Loss% × Avg Loss)

If expectancy is positive, the strategy is statistically profitable. If negative, it’s a losing strategy.

Profit Factor (robustness): Gross Profit ÷ Gross Loss

A ratio of 1.5+ is healthy. 2.0+ is excellent. Below 1.2 is risky.

Sharpe Ratio (risk-adjusted return): Shows return per unit of risk. Higher = better risk-adjusted returns. Requires more calculation.

Backtesting Is Not Live Trading

Backtests are optimistic because:

  1. No emotions: Backtest always follows rules; you might hesitate
  2. Perfect fills: Backtest assumes ideal entry/exit; real trading gets slippage
  3. No drawdown pain: Backtest shows -15% drawdown as a number; real money feels much worse
  4. No unexpected events: Backtests have historical data; black swans aren’t in the data

A strategy that backtests at 50% win rate might perform at 40-45% in live trading due to psychology and execution gaps.

Key Takeaway

Backtesting is testing strategy logic against historical data to evaluate profitability, drawdown, and expectancy before risking real capital. A profitable backtest doesn’t guarantee future success, but an unprofitable backtest is a warning sign.

Backtest rigorously: 2+ years of data, 100+ trades, check out-of-sample results, account for slippage. If your backtest is profitable with positive expectancy and acceptable drawdown, you have statistical evidence the strategy works.

Then transition to small real money and watch live results carefully. If live results match backtesting results (within 5-10%), you have a tradeable edge.

PipJournal helps you compare your backtesting statistics to live trading results. See which setups matched historical performance and which ones failed in real money. This comparison reveals where your psychology impacts execution and where your backtest assumptions were too optimistic.

Common Questions

Why is backtesting important?

Backtesting shows whether your strategy was profitable in the past. If it wasn't profitable in 500 historical trades, it's unlikely to be profitable in future trades (unless market conditions changed). Backtesting reveals win rate, drawdown, and expectancy before you risk real money.

Can past performance predict future results?

Not perfectly. Markets change. A strategy that worked in a bull market might fail in a bear market. A strategy that worked in volatile conditions might fail in flat markets. But if a strategy worked across multiple market conditions (bull, bear, ranging, choppy), it has a higher chance of working in the future.

What's curve-fitting and why is it bad?

Curve-fitting is optimizing your strategy's parameters to fit historical data perfectly. Example: backtest 1 year of data, find the 'perfect' EMA length that wins 90% of trades. Sounds great until you test it on the next year of data (out-of-sample) and it wins 30%. You fit the historical curve, not the market logic. Avoid over-optimization.

How much historical data do I need to backtest?

Minimum 1-2 years; better 3-5 years. This captures bull markets, bear markets, ranges, and various volatility environments. 1 year is often a bull or bear trending market; you need multiple years to see performance in different conditions. For backtesting to be valid, aim for 100+ trades.

What's the difference between backtesting and forward-testing?

Backtesting = testing on historical data already happened. Forward-testing (out-of-sample testing) = testing your strategy on data the strategy never 'saw' before, to prove it's not curve-fit. Example: optimize on 2020-2022, then forward-test on 2023-2024. If results are similar, it's robust.

Share this article

Track Backtesting Automatically

PipJournal calculates your backtesting and other key metrics from your trade data. Import trades and get instant insights.

SSL Secure
One-Time Payment
No credit card required
4.8/5 (47 reviews)