Why Your Backtest and Live Results Differ

·

Part of the guide: Overfitting and luck

In short

A backtest assumes ideal fills; live trading has real delays and costs. Eight common causes of the gap are next-bar fills, take profit and stop loss in one bar, slippage and latency, exchange data, repainting, regime change, overfitting and partial fills. In the post's hypothetical example, 0.15% of slippage per round trip takes a third of a +0.45% average trade.

Your backtest shows a smooth equity curve (your account balance over time). You switch the strategy on with real money, and a few weeks later the live results look nothing like it.

A backtest is a simulation. It replays historical prices and assumes how your orders would have been filled. Live trading has real orders, real delays and real costs. Most gaps between the two come from an assumption the market did not match. Below are eight common causes, a worked example and a checklist. This guide is educational only: you can lose money even after a good backtest, and past results do not predict future results.

1. Fills: bar close vs. next open

A fill is the execution of an order at a specific price. Most Pine Script strategies calculate once per bar (candle), a time slice with an open, high, low and close price. A signal is only known once its bar has closed, so by default TradingView fills the order at the open of the next bar (TradingView docs).

The setting process_orders_on_close = true fills at the close of the signal bar instead. TradingView itself calls creating and filling an order at the same instant "typically unrealistic in real-world trading".

2. Intrabar ambiguity: take profit and stop loss in one bar

A take profit (TP) closes a trade at a target gain, a stop loss (SL) at a maximum loss. When one bar touches both levels, the backtest cannot know which came first. TradingView guesses: if the open is closer to the high, it assumes open → high → low → close. Otherwise it assumes open → low → high → close (TradingView docs).

Say you are long (you bought and profit if price rises) from 60,000, with a TP at 61,200 (+2%) and an SL at 58,800 (−2%). The next 4-hour bar opens at 60,100, reaches 61,500 and drops to 58,500. The open is 1,400 below the high (61,500 − 60,100) and 1,600 above the low (60,100 − 58,500). So the backtest assumes the high came first and books a +2% win. If price really fell first, the live trade hit the stop and lost 2%. One bar, 4 percentage points apart.

TradingView's High bar-detail option (use_bar_magnifier = true in code, Premium and Ultimate plans) uses lower-timeframe bars to reduce the guesswork. Without it, count how many of your trades exit on a bar that touched both levels.

3. Slippage and latency

Slippage is the difference between the price you expected and the price you got. Latency is the delay between signal and execution: an alert fires, a bot reacts, the exchange processes the order, and price keeps moving. A market order (buy or sell now at the best available price) executes right away, but "the last-traded price is not necessarily the price at which a market order will be executed" (Investor.gov). A standard stop order becomes a market order once its stop price is reached (same source), so in a fast move a stop loss can fill well beyond its level.

Pine's slippage setting is 0 by default, and TradingView's docs call slippage "dynamic and unpredictable, making it impossible to simulate precisely" (TradingView docs). Zero means assuming the best case on every order. More in Fees and slippage in backtests.

4. Data differences between exchanges

Bitcoin does not have one single price. Each exchange matches its own buyers and sellers, so candles differ. A wick (the thin line marking a bar's high or low) that hits your stop on one exchange may not exist on another. A study of 2017–2018 data found "periods of large, recurrent arbitrage opportunities across exchanges" in crypto: the same coin traded at clearly different prices, most of all between countries (Makarov & Schoar, Journal of Financial Economics, 2020).

So backtest the market you actually trade: same exchange, same pair (BTC/USDT is not BTC/USD) and same market type. Spot means buying the coin itself; futures are contracts on its price that trade at their own prices. PineTester, for example, tests on spot data from about 25 crypto exchanges, one market per backtest. If you trade futures, treat spot results as an approximation.

5. Repainting

Repainting means a script behaves differently on historical bars than on live bars. TradingView estimates that "more than 95% of indicators in existence exhibit some form of repainting behavior" (TradingView docs). Much of it is harmless, like an RSI that moves until its bar closes. The dangerous kind feeds the backtest information that did not exist yet, such as a higher-timeframe close read before that bar had finished. TradingView calls this "dangerously misleading" (same source): it looks excellent on history and cannot happen live. Repainting and lookahead in backtests shows how to check your script.

6. Regime change

A market regime is how the market behaves over a period: trending or sideways, calm or volatile. A strategy tuned during a strong rally can struggle in a sideways market. Patterns also fade once people trade them. Across 97 published stock-return predictors, returns were 26% lower right after the original study periods and 58% lower after publication (McLean & Pontiff, Journal of Finance, 2016). Test across several years and market phases.

7. Overfitting

Overfitting means tuning a strategy so closely to past data that it captures random noise instead of a repeatable pattern. Researchers warn: "given any financial series, it is relatively simple to overfit an investment strategy so that it performs well" on the data used to design it (Bailey et al., Notices of the AMS, 2014).

Our study of 2,000 parameter combinations on BTC/USDT 4h (May 3 to August 31, 2026) shows it. The best combination made +11.27% net profit with a profit factor (gross profit ÷ gross loss) of 21.36, while simply holding BTC lost 0.57%. But it came from just 2 trades, far too few to tell skill from luck. Among results with at least 6 trades, the best was +7.58%. The parameter optimization guide covers picking settings that are more likely to hold up.

8. Partial fills

A limit order trades only at your price or better. By default, TradingView's backtest fills it as soon as price reaches your level, while its docs note that in real trading "some limit orders might not fill when the market price reaches the specified value, due to insufficient liquidity or price action" (TradingView docs). Liquidity is how many orders wait near the current price. An order can also be partially filled, with only part of it executed; Binance reports this as PARTIALLY_FILLED (Binance API docs). Larger orders in thin markets are more exposed.

What you can do about it

  • Use conservative assumptions: next-bar fills, realistic commission and slippage, and limit orders that only count as filled once price trades past them.
  • Test out of sample: optimize on one period, then check a later period you did not touch (How to backtest a trading strategy properly).
  • Paper trade: paper trading means running the strategy on live prices with simulated money. It can reveal repainting and bot errors, but not real slippage or partial fills.
  • Run a small live test: after paper trading, trade the strategy with real orders at a fraction of the size you plan to use (Risk management basics). Losses are still possible.

Worked example: measuring your real slippage

Say your BTC/USDT 4h backtest shows an average trade of +0.45% after commission, with zero slippage. You go live with a small size and log two prices per trade: the price the backtest would have used (the next bar's open) and your actual fill. Your first five long entries:

TradeBacktest priceLive fillDifferenceSlippage
160,000.0060,048.00+48.000.08%
262,500.0062,525.00+25.000.04%
358,000.0058,104.40+104.400.18%
464,000.0064,000.000.000.00%
561,000.0061,061.00+61.000.10%
Hypothetical numbers. Difference = live fill − backtest price. Slippage = difference ÷ backtest price. For a long entry, a higher fill is worse.

Average entry slippage: (0.08 + 0.04 + 0.18 + 0.00 + 0.10) ÷ 5 = 0.40 ÷ 5 = 0.08%. Say your exits, logged the same way, average 0.07% (for a long exit, a lower fill is worse). Then each round trip (entry plus exit) costs 0.08% + 0.07% = 0.15% more than the backtest assumed.

That leaves 0.45% − 0.15% = 0.30% per trade. A third of the average trade is gone (0.15 ÷ 0.45 ≈ 0.33). Over 100 trades, that is about 30 percentage points instead of 45 (a simple sum that ignores compounding). A backtest average of +0.12% would turn negative: 0.12% − 0.15% = −0.03%.

Now feed the measurement back. Pine's slippage setting counts ticks, the smallest price step of a market. With a tick size of 0.01 USDT and a price near 60,000, 0.08% is 60,000 × 0.0008 = 48 USDT, or 48 ÷ 0.01 = 4,800 ticks. Pine applies it to every market and stop order, entries and exits alike, but not to limit orders (TradingView docs). The tick count is fixed, so the percentage changes with price: at 30,000, the same 48 USDT is 48 ÷ 30,000 = 0.16%. Recalculate if your test spans very different price levels.

pine
//@version=6
// Cautious fill assumptions. slippage is in ticks: 60,000 × 0.0008 ÷ 0.01 = 4,800.
// The 0.1% commission is a placeholder: use your exchange's actual fee.
strategy(
     "Conservative test settings", overlay = true,
     commission_type = strategy.commission.percent, commission_value = 0.1,
     slippage = 4800,
     backtest_fill_limits_assumption = 2,
     process_orders_on_close = false,
     use_bar_magnifier = true
 )

float fast = ta.ema(close, 20)
float slow = ta.ema(close, 50)

if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)

if strategy.position_size > 0
    strategy.exit("Exit", "Long",
         limit = strategy.position_avg_price * 1.02,
         stop = strategy.position_avg_price * 0.98)

backtest_fill_limits_assumption = 2 counts a limit order (here the take profit) as filled only once price moves 2 ticks past it. At BTC prices, 2 ticks of 0.01 is a tiny margin; it mainly stops fills on an exact touch. use_bar_magnifier needs a Premium or Ultimate plan on TradingView. PineTester’s engine does not apply backtest_fill_limits_assumption, so a limit order fills on a touch. The bar magnifier runs on 4h and 1D charts with 1-hour bars, unless the script uses last_bar_index, last_bar_time or calc_bars_count, turns on calc_on_order_fills or requests other data; you can also switch it on or off per backtest under “Strategy properties” (limitations).

Checklist

  • Orders fill at the next bar's open (process_orders_on_close off).
  • Commission and slippage are realistic, not zero, and limit orders do not fill on a mere touch.
  • You know how many trades exit on a bar that touched both TP and SL.
  • The backtest uses the exchange, pair and market type you trade.
  • The script does not repaint: historical signals match what you saw live.
  • The test covers several market regimes and a period you did not optimize on.
  • The result rests on many trades, not one or two big winners (see also the win-rate trap).
  • You paper traded first, then ran a small live test.
  • You log backtest price vs. live fill for every trade.
  • You decided in advance which gap would make you pause the strategy.

None of these steps removes risk. They narrow the gap between simulation and reality, but live results can still be worse and you can lose money. Past results do not predict future results.

Does your best setting rest on 2 trades or 200? PineTester backtests the input ranges of your Pine Script v6 strategy on crypto spot data – up to your plan’s limit per backtest, a larger grid as a random sample – and every verdict on the results page names the documented method it rests on. Results can differ from TradingView’s Strategy Tester.

Test your strategy – one free backtest

Simulated results on historical market data. Past performance is not indicative of future results. Not investment advice.