· 8 min read

Why Your Backtest Profits Don't Match Live Trading

The 7 most common reasons Pine Script backtests fail in live markets — and exactly how to close the gap before you deploy real capital.

Bhavin Javia
Bhavin Javia
Founder, BotJockie · 22+ yrs software · 5+ yrs algo dev

You've built a strategy that shows a 60% win rate, a 2.5 Sharpe ratio, and three years of consistent equity curve growth in TradingView's strategy tester. You go live. Within two weeks, the account is down 8% and nothing looks like the backtest. Sound familiar?

This is the single most common problem in retail algo trading — and it's almost never the market's fault. The gap between backtest performance and live performance is almost always an artefact of how the backtest was constructed. Here are the seven reasons this happens, and what to do about each one.

1. Look-Ahead Bias (The Silent Killer)

Look-ahead bias means your strategy is using information it couldn't have known at the time of the trade. In Pine Script, this is most often caused by using security() calls incorrectly, or by referencing the current bar's close in a condition that should only trigger on bar close.

⚠️ Common Mistake

Using close in a condition on the same bar where the signal fires means your backtest enters at a price it couldn't have known. Always test with barmerge.lookahead_off in security calls.

The fix is to shift your signal by one bar using the [1] operator, ensuring your entry fires on the open of the next bar after your signal condition is met:

// Wrong — enters on same bar close
if ta.crossover(fast_ma, slow_ma)
    strategy.entry("Long", strategy.long)

// Correct — enters on open of next bar
signal = ta.crossover(fast_ma, slow_ma)
if signal[1]
    strategy.entry("Long", strategy.long)

2. Commission and Slippage Are Set to Zero

TradingView's default backtest settings have zero commission and zero slippage. In live markets, you're paying at minimum 0.03% per side on Indian equity (Zerodha), and significantly more in crypto. A strategy making 0.2% per trade might be profitable on paper and deeply unprofitable live once you account for real costs.

Always configure your strategy properties with realistic assumptions:

//@version=6
strategy("My Strategy",
     commission_type  = strategy.commission.percent,
     commission_value = 0.05,   // 0.05% per side
     slippage         = 2)      // 2 ticks slippage

For NSE futures, use 0.05%. For crypto spot, 0.1–0.15%. For forex, convert your spread to a percentage. Re-run your backtest with these settings — if the edge disappears, it was never there to begin with.

3. Insufficient Sample Size

A strategy tested on 50 trades over 6 months is statistically meaningless. You need a minimum of 200–300 trades across different market conditions — trending, ranging, high volatility, low volatility — to have any confidence in the results. Most retail traders backtest on whatever period happens to look good and call it validated.

Rule of Thumb

For a daily timeframe strategy, test on at least 5 years of data. For intraday (5m–1h), test on at least 2 years. Always include at least one major crash or crisis period in your test window.

4. Curve Fitting / Over-Optimisation

You ran the strategy optimiser and found the perfect RSI period of 17, the exact ATR multiplier of 2.3, and the precise MA length of 43. Your backtest looks incredible. The problem: those parameters are fitted to the specific noise patterns of your test data, not to any underlying market structure.

The solution is out-of-sample testing. Split your data: use 70% for optimisation and 30% as a true holdout set you never touch during development. If performance collapses on the holdout set, the strategy is curve-fitted. Also apply the "walk-forward" principle — if you can only justify parameters with hindsight, they're not real.

5. Repainting Indicators

Some of the most popular Pine Script indicators repaint — meaning their historical values change as new bars arrive. Any strategy built on a repainting indicator will show spectacular backtest results and terrible live results, because the historical signals look clean but the live signal arrives late or not at all.

Common repainting culprits include: Heikin Ashi candles in strategies (use regular candles for signals), certain volume profile indicators, and any script using security() with lookahead_on. Always verify that your indicator's historical values on a 3-month-old bar don't change when you reload the chart.

6. Bar Magnifier vs. Close-Only Execution

TradingView's default strategy testing only executes at bar close. But you might be setting stop-losses that would realistically trigger intrabar during a volatile session. On a daily chart, your 0.5% stop might be hit by an intraday wick and trigger a stop-out that never appears in the close-only backtest.

Enable "Bar Magnifier" in your strategy properties to test intrabar execution — but be aware this requires a higher TradingView plan tier. On lower timeframes (5m and below), close-only testing is typically adequate.

7. Market Impact and Liquidity

A backtest doesn't know how large your position is relative to the instrument's liquidity. A strategy that works beautifully with 1 lot on Nifty futures might fail at 50 lots due to market impact. Crypto microcap backtests are almost always useless because the test assumes you can fill at the close price regardless of your order size.

Always check average daily volume vs. your intended position size. A reasonable rule: your position should not exceed 1% of the average daily volume of the instrument.

The BotJockie Backtest Validation Approach

Before we deploy any strategy for a client, we run a 25-point validation checklist that covers all of the above plus a dozen more edge cases. We've built this checklist from five years of live deployment experience — the kind of failures you only see once real capital is at risk.

You can download the full checklist for free as part of our Algo Toolkit.

Free Download

25-Point Backtest Validation Checklist

The exact checklist we run before deploying any strategy to live capital. Free, no card required.

Download Free Toolkit →