Strategy

8 backtesting mistakes that make a strategy look better than it is

Look-ahead bias, repainting, overfitting, missing costs and unrealistic fills — how each one inflates a backtest, how to spot it, and how to fix it in TradingView and MT5.

A backtest is an experiment, and like any experiment it can be set up to give a flattering answer without anyone meaning to cheat. The equity curve looks smooth, the win rate looks high, and then the strategy meets live markets and behaves like a different system.

Most of that gap comes from a short list of mistakes. Here they are, with the symptom that usually gives each one away and how to fix it.

1. Look-ahead bias

The strategy uses information that wasn't available at the moment of the decision. Classic examples: entering at a bar's close using a condition calculated from that same bar's high, or pulling higher-timeframe data that includes the still-forming candle's final value.

In Pine Script, the most common source is request.security() with lookahead = barmerge.lookahead_on applied to the current higher-timeframe bar. The safe pattern offsets the series by one bar so only confirmed values are used:

//@version=6
indicator("Confirmed higher-timeframe EMA", overlay = true)

tf = input.timeframe("D", "Higher timeframe")
htfEma = request.security(syminfo.tickerid, tf, ta.ema(close, 20)[1], lookahead = barmerge.lookahead_on)

plot(htfEma, "HTF EMA (confirmed)", color = color.orange, linewidth = 2)

Symptom: results that seem too good, especially entries that catch exact highs and lows.

2. Repainting

A repainting indicator changes its past signals as new data arrives. On historical bars every signal looks perfect because it was drawn with hindsight; in real time, signals appear and disappear. Pivots, zigzags and unconfirmed higher-timeframe values are frequent culprits.

Fix: act only on confirmed bars (barstate.isconfirmed in Pine, new-bar logic in MQL5), and watch the script in real time — on bar replay or a live chart — before trusting its historical signals.

3. Overfitting

With enough parameters you can fit almost any history. A strategy with an RSI length of 13, a threshold of 31.5, a 187-period EMA and a session filter from 08:15 to 10:40 has probably found noise, not an edge.

Fixes:

  • Keep parameters few and round.
  • Check neighbouring values: if RSI 13 works but 12 and 14 don't, be suspicious.
  • Split the data. Optimise on one period, then test untouched on another (out-of-sample). Walk-forward testing repeats this across rolling windows.

4. Ignoring trading costs

Spread, commission, slippage and overnight swaps are small per trade and enormous across hundreds of trades. A scalping strategy that makes 3 pips per trade before costs can easily lose money after a 1-pip spread and commission.

Fix: in TradingView, set commission_type, commission_value and slippage in your strategy() declaration. In MT5, test with your broker's real spread and commission. Then run the expectancy calculator with your after-cost average win and loss.

5. Unrealistic fills

Backtesters have to guess what happened inside each bar. A limit order "filled" because price merely touched the level, or a stop and a target inside the same bar resolved in your favour, can inflate results.

Fixes: in TradingView, use the Bar Magnifier option where your plan supports it, and be sceptical of tight targets on higher timeframes. In MT5, prefer "Every tick based on real ticks" over "Open prices only" or "1 minute OHLC" whenever intrabar behaviour matters.

6. Too few trades

Twenty trades can produce almost any win rate by chance. A strategy needs enough trades, across different conditions, for the averages to mean something. There's no magic number, but conclusions drawn from a few dozen trades should be held loosely.

7. One market regime

A trend-following system tested only during a long, steady trend will look brilliant. So will a mean-reversion system tested only in a range. Make sure the test period includes trends, ranges, and both high and low volatility — and look at results per year or per quarter, not just in total.

8. Survivorship bias and data quality

Testing a stock strategy only on companies that exist today ignores the ones that were delisted, which flatters results. In forex and CFDs, gaps in tick data, differences between broker feeds and missing sessions can distort tests too.

A quick diagnostic table

MistakeTypical symptomFirst thing to check
Look-ahead biasEntries at exact turning pointsHigher-timeframe requests, same-bar conditions
RepaintingSignals move or vanish livePivots, unconfirmed values
OverfittingGreat in-sample, poor out-of-sampleNumber of parameters, neighbouring values
Ignored costsMany tiny winnersCommission, spread and slippage settings
Unrealistic fillsTight targets always hit firstIntrabar modelling, Bar Magnifier
Too few tradesResults swing with small changesTrade count
One regimeProfits concentrated in one periodYearly breakdown
Survivorship or dataSmooth curve on a curated universeSymbol list, data source

What a good test looks like

A trustworthy backtest is usually a little boring: modest returns, costs included, drawdowns you could actually sit through, similar behaviour across periods and markets, and few parameters. Look at the maximum drawdown and the longest losing streak as carefully as the profit — the drawdown calculator shows what those numbers feel like on a real balance.

Then forward-test on a demo account. Live behaviour is the final check that no backtest can replace. For EAs specifically, our MQL5 Expert Advisor risk checklist covers the live-trading safeguards.

Try it with Edgoro

Edgoro can write your idea as a TradingView strategy() script with commission and slippage already set, or as an MT5 Expert Advisor ready for the Strategy Tester. Ask it to keep higher-timeframe requests non-repainting and to expose only the parameters you really need. Build and test your idea free.

Backtested results are hypothetical and do not guarantee future performance. Trading involves substantial risk of loss.

Build it with Edgoro

Describe your strategy in plain English and get a TradingView indicator in Pine Script v6 or a MetaTrader 5 Expert Advisor in minutes. Three generations are free.

Start free