Skip to main content
← Back to blog

Why Your Pine Strategy Wins in Backtest and Loses Live: 5 Measured Causes

📅 Published
✍️ Strategy Arena
TradingView Pine Script backtest overfitting live trading fees request.security research

A Pine strategy that wins in backtest and loses live was almost always chosen among many trials, then judged on the data used to choose it. On top come missing fees and slippage, stop or limit orders filled too favourably inside the bar, and a request.security call that reads the future.

Updated 17 October 2026. Research on past data, not investment advice.

The five causes in one table

# Cause What we measured The test to run
1 Uncounted multiple selection on pure noise, without counting, deflated Sharpe ≥ 95% in 64 to 86% of sessions; with counting, 0 to 1% declare every trial, deflate the Sharpe
2 No sealed period +172.7% in training, −37% on unseen data; Turtle 20/10 from +31.9% to −42.1% seal the end before any tuning, open it once
3 Fees and slippage 258 round trips at 0.10% per side leave 59.7% of capital; an RSI signal goes from +0.027% to −0.173% real fees, then 2x, then 3x + 5 basis points
4 Stop or limit orders inside the bar a trade identical to the tick only exists with the same assumed intrabar path (62/62) stop and target in the same bar, unfilled limits
5 request.security reading the future 258/258 and 420/420 identical trades with lookahead_off and alignment with no look-ahead lookahead_off, [1] offset, warning banner

The first two causes are statistical: they manufacture a result that does not exist. The next three are mechanical: they make a real result look better than the market will pay.

1. Multiple selection was not counted

When you try 10/40, 15/60, 20/50 and keep the best, the best score drifts mechanically away from the true expectancy. The more you try, the further it drifts. The Strategy Tester shows the result of the setting you kept; it does not know how many were discarded.

We measured it on data where no strategy can win: 350 sessions of an automated research loop on pure noise (synthetic series of 6,000 4h bars, 10 basis-point fees), roughly 300 to 400 trials per session on CPU, 3,500 to 4,700 with the GPU (protocol and results):

  • the loop believes it is improving in 88 to 98% of sessions;
  • without counting trials, its deflated Sharpe exceeds 95% in 64 to 86% of sessions;
  • with every trial counted, 0 to 1%.

A real case in the Lab: DeepSeek swept 2,000 variants of a moving-average crossover and kept the best, at +35.8% on the test period. Re-judged with its 2,004 trials declared, the same family gave a deflated Sharpe of 0.7%: no evidence of an edge (the full path).

The test: write down every combination tried. That number goes into the deflated Sharpe. The trials to declare are those used to choose this rule, not the whole project's history.

2. No period was sealed

A result obtained on the bars used for tuning is a training score. The gap with unseen data can be huge:

  • GPU genetic search: 24 million backtests, a champion at +172.7% on its training period, −37% on data it had never seen (post-mortem).
  • Turtle 20/10 on EUR/USD: +31.9% in training, −42.1% over 2013-2026 (1,306 variants judged).
  • Sealed AI leaderboard: GPT 5.6 Sol's first strategy claimed +254.52% on its research data and made +20.91% on the sealed period (leaderboard).

Looking at the end of the data "just to see", then tweaking a parameter, turns the test period into a training period. In the DeepSeek session above, the sweep's "holdout" column overlapped the test period: the +35.8% had never been judged out of sample.

The test: fix the cut-off before any tuning (the Lab seals the last 30% by default and writes the seal to disk), tune on the start, open the end once. Manual method in TradingView Basic: test a Pine strategy out of sample for free. Detection: overfitting, the 6 tests.

3. Fees and slippage were missing

In Pine, slippage is declared in ticks and is 0 by default (TradingView documentation). If the script declares no commission, check the one in the Properties tab.

By simple arithmetic, for a strategy 100% invested on each trade, the share of capital left after fees alone:

Round trips 0.05% per side 0.10% per side 0.20% per side
100 90.5% 81.9% 67.0%
258 77.3% 59.7% 35.6%
500 60.6% 36.8% 13.5%

258 is the trade count of a Pine export replayed in a real TradingView at 0.10% per side. On a short signal the gross edge vanishes: the best "RSI below 30" cell on BTC 1h went from +0.027% per episode to −0.173% after a 0.20% round trip (study). Details: fees and slippage in the Strategy Tester.

The test: real fees, then the same frozen strategy at 2x fees, then 3x plus 5 basis points, without re-tuning. That is the Lab's default stress. If the gain survives only at exact fees, it is fragile.

4. Stop and limit orders were filled inside the bar

A backtest sees only four prices per bar. To decide whether a stop or target was hit, TradingView's simulator assumes a path inside the bar (open, high, low, close, or the reverse depending on the bar) and no price gap inside it. Limit orders are filled at the requested price or better; live, they may not fill at all. Intrabar detail (Bar Magnifier, use_bar_magnifier) is reserved to some paid plans.

What we measured is the other side: parity requires declaring that path. A Lab export with a stop entry order (buy if price rises 2% above the bar's high, 5% target, 4% stop) gives 62 of 62 identical trades in the real TradingView, final capital 12,369.19 on both sides: 62 entries at the exact stop level rounded to the tick, 32 exits at target and 30 at stop. That equality only exists because the export receipt fixes the intrabar path (tv_ohlc_path) and the tie-break when stop and target fall in the same bar. The same check first found a real defect: the Pine template for the stop order crashed at the first fill, because Pine v5 evaluates both sides of an and (trade-by-trade check).

Parity says the two engines make the same assumption. It does not say the market will honour it. We have not published a measurement of the gap between this assumed path and real fills: that is a limit of our numbers.

The test: count the trades where stop and target fall in the same bar; if there are many, the result depends on the assumed path. Check process_orders_on_close. For limit orders, remove the fills at the exact price and see what is left.

5. request.security was reading the future

The classic case: request.security on a higher timeframe with lookahead_on. In backtest the daily bar "knows" its close in the morning; live it does not. TradingView's documentation describes this as a source of future data on historical bars.

What we measured: the Lab's Pine exports explicitly write lookahead_off, and the Lab aligns a second market with no look-ahead. An export that follows ETH read through request.security gives 258 of 258 identical trades in TradingView; a newer version, over a long window with close@ETHUSDT, 420 of 420, then 5 more trades on the TradingView side, all entered after the last ETH bar the Lab had. The remaining gap comes from data coverage, not from look-ahead. As of 12 October 2026, the Lab's Pine import refused request.security in a script rather than guess its intent.

The test: search the script for lookahead_on, add a [1] offset to the higher-timeframe values, re-run. If the result collapses, it came from the future. Also read the report's warning banner if it appears.

What about a regime change?

A sixth cause is not a backtest flaw: the market changes. In our walk-forward test of five well-known trend strategies over 2019-2025, all of them protected in the fold containing the 2022 drop, and all five lost the last fold against buy-and-hold (for example Faber −50.2% vs +99.7%) (results). The only test is to judge the rule over several cycles, fold by fold, without re-tuning in between.

Before risking money: the checklist

  1. Seal a period before any tuning, open it once.
  2. Count every trial and deflate the Sharpe.
  3. Recompute at 2x then 3x fees, slippage included.
  4. Count the bars where stop and target both get touched; do not trust a limit order filled at the exact price.
  5. Check lookahead_off and a [1] offset on data from another timeframe.
  6. Compare with buy-and-hold over the same window.

  7. Free online judge: the script against buy-and-hold on a sealed period, fees included.

  8. The free Lab (Windows and Linux): sealed period, counted trials, fee stress, "survives", "no evidence of an edge" or "inconclusive" verdict, then a Pine export to replay trade by trade.
  9. Check the trades in TradingView: replay the export and compare. Open TradingView (partner link).

FAQ

Why does my Pine Script strategy win in backtest but lose money live?

Most often because its settings were chosen among many trials on the very period where it is judged. The other common causes are missing fees and slippage, stop or limit fills that are too favourable inside the bar, and a request.security call that reads data not yet known.

Is my TradingView backtest wrong?

Rarely in the arithmetic: our Pine exports replayed in a real TradingView gave the same trades as our engine (258 of 258, 62 of 62, 519 of 519). It is the assumptions (selection, fees, intrabar path, look-ahead) that make it misleading.

How many trials should I declare?

All the ones used to choose the rule: every parameter combination tested, every variant dropped. Not the whole project's history. The deflated Sharpe corrects the result for that number.

Is paper trading enough to validate a strategy?

It tests execution on new data, which is useful, but over a short period. It complements a period set aside before any tuning; it does not replace it.

Can a strategy that loses live be fixed?

Changing the parameters after the failure is a new trial, tuned on data you have now seen. It needs a new, never-seen period to be judged.

Sources

Disclosure: Strategy Arena takes part in the TradingView partner program. If you create a new account through our links and then subscribe on the web, we may earn a commission at no extra cost to you. It changes no number and no verdict in this article.

Research on past data, not investment advice. No past result guarantees a future one.

⚠️ Disclaimer — This article is for informational and educational purposes only. It does not constitute investment advice or a buy/sell recommendation. Past performance does not guarantee future results. Strategy Arena is an educational simulator with virtual capital. Always do your own research before making investment decisions.

Enjoyed this article? Share it

𝕏 Share on X ✈️ Telegram

Turn a local result into durable proof

The Lab runs free on your PC. Certificates and audit dossiers use credits: 1 credit = 1 certificate or 1 dossier, 2 offered when you open an account; paying never changes the verdict.

Get the Lab (free)Audit a TradingView export Pricing and credits Publish a Lab Report Lab Reports Hall
TradingView Starter
Choose the account path. Prove the strategy separately.
Your first chart and price alert do not require the Lab. Strategy Arena proof remains required before trusting or exporting a strategy.
Partner attribution is for first-time users and web purchases only. Strategy Arena may earn a commission on eligible purchases; starting with a free account needs no payment.
I have never had an account · Start free I already have an account Check a strategy
More TradingView paths
Evidence-gated Pine review