Skip to main content
Building a Simple System

How to Backtest Your Trading System Correctly

Pomegra Learn

How to Backtest Your Trading System Correctly

Before you risk a single real dollar on your trading system, you must test it on historical data. This is called backtesting. Backtesting is the only way to measure whether your system actually makes money or whether your brain is fooling you into thinking it works. Most traders skip this step, lose money, and quit. The traders who backtest their systems properly—and understand the limitations of backtests—become the profitable ones.

Quick definition: Backtesting is the process of applying your trading rules to historical price data to simulate how your system would have performed in the past, measuring win rate, profit factor, drawdown, and other metrics before risking real capital.

Key Takeaways

  • Backtesting requires at least 50–100 trades of historical data to reveal if your system is genuinely profitable
  • The biggest backtesting mistake is curve-fitting—designing your system to match past prices so well it fails on new data
  • Always test on out-of-sample data (data your system has never seen) to verify it's not just lucky
  • Use realistic assumptions: slippage, commissions, spreads, and gaps will hurt your backtest results
  • A backtest that shows 80% win rate but 20% monthly drawdown is worse than one showing 40% win rate with 5% drawdown

Why Backtesting Matters

Every trader thinks their system works. But thinking and knowing are different. A backtest forces you to be honest. You feed your system's rules into historical data and it tells you exactly how many trades would have won, how many would have lost, and how much capital you would have made or lost.

The U.S. Securities and Exchange Commission (SEC) recommends backtesting as a standard risk-management practice. Financial advisors who use algorithmic strategies must backtest and document their performance. The reason: traders who skip backtesting lose money 70% of the time.

In 2015, a famous day trader shared his "absolutely reliable" breakout system on social media. Win rate: 75%, average profit per trade: $800, "tested on 2008 data." A thousand people paid him for the system. When they tested it on 2015 live data, the win rate dropped to 38% and the average loss exceeded the average win. His system was perfectly designed for 2008 but completely broken for modern markets. This is curve-fitting, and it happens because he never tested on out-of-sample data.

Manual Backtesting vs. Automated Backtesting

Manual Backtesting (The Beginner's Method)

Manual backtesting means you:

  1. Open a historical chart (1–2 years of data)
  2. Go back to a start date (e.g., January 2023)
  3. Scroll forward bar by bar
  4. Every time your entry rules are met, you document a trade
  5. You calculate profit/loss based on your stop and target
  6. You continue until you reach the end of the data

Advantages:

  • Builds intuition for how your system performs across market conditions
  • Forces you to think critically about each trade
  • No software required—just a chart and a spreadsheet

Disadvantages:

  • Errors in calculation are common
  • Slow (20–30 trades takes 2–3 hours)
  • Psychological bias: you'll unconsciously favor the trades that worked

Tools: TradingView (free), MetaTrader 4 (free), or a simple spreadsheet.

Automated Backtesting (The Professional Method)

Automated backtesting uses software to feed your system's rules into historical data automatically:

  1. You code your entry rules into a program
  2. The program applies those rules to every bar of historical data
  3. It calculates every trade, win/loss, and performance metric
  4. You get a report showing profitability, drawdown, and consistency

Advantages:

  • Removes manual calculation errors
  • Tests 100+ trades in seconds
  • Scalable—test multiple systems at once
  • Can optimize parameters systematically

Disadvantages:

  • Requires coding knowledge (Python, Pine Script, C#)
  • Easy to curve-fit without realizing it
  • Results can be overly optimistic (not accounting for slippage/gaps)

Tools: MetaTrader 4 (built-in), ThinkorSwim (free), Python + Backtrader (free), AmiBroker (paid), NinjaTrader (paid).

The Four Backtesting Errors You Must Avoid

Error 1: Curve-Fitting (Overfitting)

Curve-fitting is designing your system to match the exact price movements of your historical data. You look at past prices and say: "If I had bought at this level and sold at that level, I'd have made 50% annually." So you build rules around those exact prices.

The problem: those exact conditions won't repeat. You've designed a system that's perfectly optimized for the past but useless for the future.

Example of curve-fit:

  • You test on EUR/USD from 2020–2023 (your historical data)
  • You find that buying every time RSI drops below 25 works in 2020 and 2021
  • You add 15 more conditions to make it even more profitable on 2020–2023 data
  • By 2024, it's completely broken because you over-optimized for conditions that no longer exist

How to avoid it:

  • Keep your system simple: 3–5 entry rules maximum
  • Test on different time periods separately (2020 results vs. 2021 vs. 2022)
  • If your system works great on 2020 but fails on 2021, it's curve-fitted to 2020
  • If your system works consistently across all time periods, it's likely genuine

Error 2: In-Sample Bias

In-sample data is data you used to design your system. Out-of-sample data is data you haven't looked at yet. If you test only on in-sample data, you're cheating.

The mistake: You design your system on January–August 2023 data, then backtest on January–August 2023 data. Of course it works—you built it for that exact period.

The solution: Use the 80/20 split.

  • Split your historical data into two parts: 80% (in-sample) and 20% (out-of-sample)
  • Design your system on the 80% data
  • Test final performance on the 20% data you never looked at
  • If it works on both, it's real. If it fails on 20%, it's curve-fitted.

Example:

  • In-sample period: Jan 2020 – Sep 2023 (your testing ground)
  • Out-of-sample period: Oct 2023 – Dec 2023 (your truth check)
  • Design and optimize on Jan–Sep data
  • Verify on Oct–Dec data
  • If Oct–Dec shows similar win rate and profit factor as Jan–Sep, you're good

Error 3: Ignoring Transaction Costs

Your backtest shows 45% annual return. But that assumes every trade executes at your exact price with zero cost. Reality is harsher:

  • Slippage: You want to buy at $100, but by the time your order fills, it's $100.05. Slippage per trade: $5.
  • Commissions: Your broker charges 0.05% per trade. On a $10,000 position, that's $5 per trade.
  • Spread: The bid-ask spread on your asset is 0.01%, costing $1 per trade on a $10,000 position.
  • Gaps: Overnight news causes EUR/USD to gap 30 pips. Your stop-loss at 1.0850 fills at 1.0820 instead. You lose an extra $300.

If you ignore these, your backtest is a fantasy. Your real live results will miss your backtest target by 5–15%.

How to account for it:

  • Forex: Add 1–2 pips per trade for slippage + spread
  • Stocks: Add 0.1% commission + 0.01% spread per trade
  • Futures: Add 1 tick of slippage + exchange fees per trade
  • Gaps: Widen your stop-loss by 10–20% to account for overnight moves

Revised example:

  • Backtest shows $50,000 profit on 100 trades
  • Subtract 5 pips slippage on each of 100 EUR/USD trades: 100 × 5 pips × 100,000 units × (1 pip value) = roughly $5,000
  • Subtract broker commissions: 100 × 0.05% × average position size
  • Revised profit: $50,000 - $5,000 - $2,500 = $42,500 (15% reduction)

Error 4: Cherry-Picking Entry/Exit Timing

In a backtest, you know exactly what the price is every bar. In real life, you don't. Your entry rule might say "buy when price closes above the 20MA," but what price do you use—the open, close, or high of that bar? In a backtest, it's obvious. In live trading, you're placing a market order into uncertainty.

The mistake: Your backtest assumes you enter at the exact close price. Your backtest shows $5,000 profit. But in live trading, you entered at the open or worse, due to gapping and slippage.

How to avoid it:

  • Use realistic entry timing: market orders fill at the next bar's open (not the close you see in the backtest)
  • Use realistic exit timing: if your target is the high of a bar, assume you fill at the high, but if you're exiting on a stop, assume you fill 5–10 pips worse than your stop price
  • Test with 1-minute data if you're trading 4-hour charts, to see how intrabar movement affects fills

The Six-Step Backtesting Process

Step 1: Define Your System Clearly

Write down your exact rules in a way a robot could understand:

ENTRY RULE:
IF (Close > Moving Average 50)
AND (RSI > 50)
AND (Volume > 20-day average)
THEN Buy 1 contract

EXIT RULE:
IF (Close < Moving Average 20)
OR (Profit target of 150 pips reached)
OR (Stop-loss 40 pips hit)
THEN Exit position

No vague language. No "looks strong." No "feels right." Only testable conditions.

Step 2: Collect Historical Data

Gather at least 2 years of price data. The more data, the better.

  • Stocks: Use Yahoo Finance (free) or your broker's data
  • Forex: Use TradingView (free charts) or OANDA (free data)
  • Futures: Use your broker's data tools
  • Crypto: Use CoinGecko or Binance (free historical data)

Make sure the data includes:

  • Open, High, Low, Close prices
  • Volume
  • Splits and dividends (if stocks)

Step 3: Split Your Data

Divide your data into two parts:

  • 80% in-sample: Design and optimize your system here
  • 20% out-of-sample: Test without optimization

Example timeline:

  • In-sample: Jan 2020 – Aug 2023
  • Out-of-sample: Sep 2023 – Dec 2023

Step 4: Run Your Backtest

Use manual or automated testing. Record:

  • Number of trades
  • Winning trades
  • Losing trades
  • Win rate (wins ÷ total trades)
  • Average profit per winning trade
  • Average loss per losing trade
  • Total profit/loss
  • Maximum consecutive losses
  • Maximum drawdown
  • Profit factor (sum of wins ÷ sum of losses)

Example results table:

MetricValue
Total Trades47
Winning Trades22
Losing Trades25
Win Rate46.8%
Average Win$850
Average Loss-$600
Gross Profit$18,700
Gross Loss-$15,000
Net Profit$3,700
Profit Factor1.25
Max Consecutive Losses4
Max Drawdown8.2%

Step 5: Analyze on Out-of-Sample Data

Now test the exact same system on the 20% data you never looked at:

MetricIn-SampleOut-of-SampleMatch?
Win Rate46.8%44.2%✓ Similar
Profit Factor1.251.19✓ Similar
Max Drawdown8.2%9.1%✓ Similar

If in-sample and out-of-sample results are similar, your system is likely real. If out-of-sample is dramatically worse, you've curve-fitted.

Step 6: Optimize (Carefully)

Once you've verified your system works out-of-sample, you can tweak it:

  • Adjust parameters (MA period from 50 to 55, RSI threshold from 50 to 45)
  • Test in-sample again
  • Verify the changes on a new out-of-sample set

But never optimize to the point where in-sample looks perfect and out-of-sample falls apart.

Example Backtest: A Real Trading System

System: Moving Average Crossover

  • Buy when the 20-period MA crosses above the 50-period MA
  • Sell when the 20-period MA crosses below the 50-period MA
  • Tested on: EUR/USD 4-hour chart, Jan 2020 – Dec 2023

In-Sample Results (Jan 2020 – Sep 2023):

  • Total trades: 34
  • Win rate: 52.9%
  • Profit factor: 1.48
  • Total profit: $12,400
  • Max drawdown: 6.1%

Out-of-Sample Results (Oct 2023 – Dec 2023):

  • Total trades: 8
  • Win rate: 50%
  • Profit factor: 1.42
  • Total profit: $2,900
  • Max drawdown: 5.8%

Conclusion: The out-of-sample results are similar to in-sample. The system isn't curve-fitted. It shows consistent 50%+ win rate and 1.4+ profit factor. This is a candidate for live testing.

Flowchart: Backtesting Decision Tree

Real-World Examples

Example 1: The Honest Backtest (2022) A trader backtested a breakout system on GBP/USD daily charts from 2015–2021 (in-sample) and 2022–2023 (out-of-sample). In-sample: 55% win rate, 1.6 profit factor, $18,000 profit. Out-of-sample: 52% win rate, 1.54 profit factor, $4,200 profit. The out-of-sample results were roughly proportional (fewer trades due to shorter period). He proceeded to live trading and earned consistent 2–3% monthly returns for two years.

Example 2: The Curve-Fitted Disaster (2021) A trader used 50 different variables in his entry rules, optimizing them obsessively on 2018–2020 data. His backtest showed 78% win rate and 12% monthly returns. He launched it live in January 2021. By March 2021, he lost 40% in real trading. Why? His system was designed for 2018–2020 price behavior. When 2021 volatility patterns changed, every rule fell apart. He never tested out-of-sample.

Example 3: Transaction Costs Destroy Dreams (2023) A day trader backtested a 5-minute chart scalping system, assuming each trade had a 10-pip profit. Without slippage, he calculated 35% annual return. But his actual execution costs were: 2 pips average slippage + 1 pip spread + 1 pip commission = 4 pips per trade. His actual 10-pip profit became 6-pip profit (40% reduction). His annual return dropped from 35% to 21%. If he'd accounted for costs in the backtest, he'd have sized his risk correctly and been fine.

Common Backtesting Mistakes

Mistake 1: Testing Only Your Winners You backtest only the last six months (when your system worked great), not the prior two years (when it struggled). You're cherry-picking.

Mistake 2: Manually Choosing When to Trade Your rule says "trade breakouts," but you backtest only the obvious, perfect breakouts and skip the ambiguous ones. In live trading, you get ambiguous setups too.

Mistake 3: Assuming Perfect Liquidity You test on major currency pairs assuming you can enter/exit instantly. But at 3 AM GMT, EUR/USD can have 5-pip spreads. In a backtest, you assumed 1-pip spread.

Mistake 4: Not Accounting for Gaps Your backtest uses daily closes. But the market gapped 100 pips at the open overnight. Your stop-loss didn't execute at the price you expected; it slipped 100 pips worse.

Mistake 5: Ignoring Correlation You have three separate trading systems, each showing 2% monthly return. You backtest them individually. But when you run all three simultaneously, they all fail at the same time because they're correlated. Portfolio backtesting (testing all systems together) is necessary.

Mistake 6: Falling in Love with "High Win Rate" Your backtest shows 75% win rate. You're excited! But your average win is $500 and average loss is $2,000. Your profit factor is 0.8—you lose money. A 40% win rate with $2,000 average win and $500 average loss is far better (profit factor 1.6).

FAQ

How much historical data do I need to backtest?

At least 1–2 years of data for swing trading and longer timeframes, 3–5 years for day trading. More data is better because it captures different market regimes (trending, ranging, volatile, calm). If you backtest only 6 months of data, you might get lucky with great market conditions and miss the inevitable bad periods.

Can I backtest on 1-minute data if I trade 4-hour charts?

Yes, and you should. 1-minute data shows intrabar movement and gaps that daily data doesn't capture. But it's slower. A practical approach: design your system on daily data, then backtest it on 1-hour or 4-hour data to refine entries/exits.

What is a "good" profit factor?

A profit factor of 1.5+ (wins ÷ losses) is solid. 1.3–1.5 is acceptable. Below 1.2, your system barely covers transaction costs. Above 2.0, you might be curve-fitted.

Should I optimize my moving average period from 50 to 49 if it improves backtest results?

Only if it's a meaningful improvement (win rate +5%, profit factor +0.1+) AND it improves out-of-sample results too. Optimizing a parameter by 1–2 units is usually curve-fitting. Be conservative.

What's the difference between backtesting and forward testing?

Backtesting uses historical data you've already seen. Forward testing uses future data you haven't seen yet (paper trading, demo accounts). Always do both.

Can I backtest using just my broker's account?

Yes, some brokers (MetaTrader, ThinkorSwim) have built-in backtesting tools. But be aware: their data quality varies, and they might not account for slippage accurately. For precise backtests, use dedicated backtesting software.

How often should I update my backtest?

Once per quarter after 50+ live trades. Compare your live results to your backtest. If they match, your backtest is accurate. If they diverge, investigate why (data quality, market regime change, execution issues).

Summary

Backtesting is the reality check between your belief that a system works and the data-driven truth. Use at least 80/20 split of in-sample and out-of-sample data. Avoid curve-fitting by keeping rules simple and testing across different time periods. Account for real-world transaction costs: slippage, commissions, spreads, and gaps. A backtest that shows consistent 40–60% win rate with 1.3+ profit factor, tested on out-of-sample data, is ready for forward testing. A backtest showing 80% win rate on in-sample but 40% on out-of-sample is curve-fitted and will fail live. Respect the backtest results and only risk real capital after your system has proven itself across multiple market regimes.

Next

Forward Testing and Paper Trading