Skip to main content
← Back to blog

How to Test a Pine Script Strategy on Data It Has Never Seen

📅 Published
✍️ Strategy Arena
pine script backtest out of sample overfitting tutorial free

Short answer: to test a Pine Script strategy on data it has never seen, keep the last part of the history closed while the strategy is built, then replay the unchanged script on it once. Strategy Arena's free online judge does this in your browser: it seals the last 20% of the candles (BTCUSDT or your own CSV), replays your Pine v5 script, and returns survives, mirage, inconclusive or not enough trades, with the exact rule where the strategy falls.

Paste your Pine strategy into the online judge → No account, no install. Research on past data, not advice.

Why a backtest that keeps nothing aside proves little

A strategy report computed on the full history you used to pick the rules answers one question: how well do these rules fit this history? If you tried a few lengths, thresholds or filters and kept the best one, part of that result is the noise of that particular history. The report looks the same whether the rule found something or only memorized the past.

That is one common reason a TradingView strategy that looks strong in the backtest disappoints live: the live period is the first data the rule has truly never seen.

The fix is old and simple: split the history before you look.

Part Share What happens there
Training first 80% of the bars the script runs; this is where a result can be tuned, even unintentionally
Sealed period last 20% of the bars kept closed; the unchanged script is replayed on it once, and the verdict rests on it

When the training result is strong and the sealed result collapses, we call it a mirage: the result existed only on the data it was built on. A sealed period is still past data. It does not predict the next month; it only tells you whether the result held once outside the data it was tuned on.

Step by step: judge your strategy in the browser

1. Paste the strategy

Open the online strategy judge and paste a complete Pine Script v5 strategy(...). The judge reads the script's own settings: capital, position size, commission, slippage and fill timing. With process_orders_on_close=true orders fill at the close of the signal bar; without it, at the next open, as on TradingView. If the script declares no commission, the judge applies 10 bps per fill.

If the importer cannot carry a construction without changing the rule, the judge refuses the script and names the reason, the function and the line, rather than testing an approximate strategy.

2. Choose BTCUSDT or your own candles

By default the judge uses Binance BTCUSDT: 1D (full history), 4h (3 years) or 1h (1 year).

Since 6 November 2026 you can load your own candles: a CSV file with time, open, high, low, close, volume, from a source whose terms allow your own backtest. The file is read in your browser and is not sent to our server. You stay responsible for your rights to the data you load.

One example of such a source is Binance Vision (data.binance.vision), whose terms permit algorithmic historical backtesting for purely personal, non-production research (CC BY-NC-SA 4.0). To get a monthly file, following the official README:

  1. Pick the market, the symbol and the interval, then build the path: https://data.binance.vision/data/spot/monthly/klines/BTCUSDT/1h/BTCUSDT-1h-2026-09.zip (symbol, interval, year and month appear in the name).
  2. Download the .zip and its .CHECKSUM file from the same folder, and check it: sha256sum -c BTCUSDT-1h-2026-09.zip.CHECKSUM on Linux, shasum -a 256 -c … on macOS.
  3. Unzip it and drop the .csv on the judge.

Spot files have no header row; the judge then reads the columns in the order time, open, high, low, close, volume and shows a warning. Since 1 January 2025, Binance Vision spot timestamps are in microseconds; the judge reads seconds, milliseconds, microseconds and ISO 8601 dates.

The judge needs at least 300 candles. One month of 1h bars is about 720 candles, enough to run. One month of 1D bars is only about 30: join several monthly files into one CSV first (we checked on 6 November 2026 that ten 2026 daily files joined into one, 304 bars, are read as 1D with a 0.01 tick). Below one day, the judge keeps the last 8,760 bars. The tick is estimated from the price decimals and can be corrected; it only matters if the script declares slippage.

With your own candles there is no public share card, because the server cannot check your file. The receipt shows the file's SHA-256 instead.

3. Read the verdict and "Where the strategy falls"

The judge returns one of four verdicts. Under it, the Where the strategy falls panel lists the engine's rules in the order it applies them, each with its value and its threshold. The rule that decides is in red, and the step where the judge stops is labelled "the judge stops here". A chart, Before and after the seal, shows the training result, then the sealed result and holding the asset, with a dotted line for "if the training pace had carried on". The break is visible at the angle.

Step Rule (free mode) Verdict if it fails
1. Enough trades? at least 10 training trades before the seal is opened; at least 10 trades on the sealed period not enough trades
2. Mirage? no loss on the sealed period; deflated Sharpe on training at least 50% mirage
3. Holds? better than holding the asset; random markets do as well 5 times in 100 at most (SPA test, 1,000 replays or more); deflated Sharpe at least 95% inconclusive

Pass all three and the verdict is survives the unseen test. Certified mode adds stricter rules, such as a minimum number of independent events.

4. What to do with each verdict

  • Not enough trades: no conclusion either way. Try a longer history or a shorter timeframe with the same script. Editing the rules to trade more makes a new script, which deserves its own sealed period.
  • Mirage: the result did not hold outside its training data. Tuning the same rule until the sealed period turns green would spend that period: once you have looked, it is no longer unseen. Keep a newer period aside for the next idea.
  • Inconclusive: the script did not lose money, but at least one "holds" rule failed, often against holding the asset or against random markets. A lead to study further, not evidence.
  • Survives: one sealed period, one asset, one timeframe. A reason to test elsewhere, not a forecast.

A real example: the MACD crossover, a mirage on 1D

We took the exact MACD crossover script published in our article 7 free Pine Script strategies (10% of equity per entry, 0.1% commission, slippage=1, fills at the next open) and judged it on BTCUSDT daily candles on 6 November 2026. Window: 3,348 daily bars, from 17 August 2017 to 16 October 2026; sealed period from 17 December 2024.

Measure Value
Training (80%): result, trades +57.64%, 91 trades
Sealed period (20%): result, trades −0.52%, 28 trades
Holding BTC over the sealed period −23.26%
Deflated Sharpe, training 99.9%
Random markets doing as well (SPA) 42.4%
Verdict Mirage (rule: loss on the sealed period)

"Where the strategy falls" reads: enough trades (28, threshold 10), then the sealed result in red, −0.52% against a threshold above 0. The judge stops at step 2. The greyed step 3 is shown for information: the script lost far less than holding BTC (+22.74 points), but random markets did as well 42.4 times in 100. A loss on the sealed period stays a mirage even when holding lost more.

The same exact script was inconclusive on 4h (49 trades) and a mirage on 1h (65 trades) on the same day. None of the seven scripts in that article survived.

Limits of the judge

  • Pine v5 only, and only the subset the importer supports. A refused script gets the exact reason; the judge never substitutes an approximate strategy.
  • Constructions refused: anything whose conversion would change the rule. Slippage is counted as an extra fee at its worst case on the data, and refused when that worst case exceeds 1 bp per fill or the value is not a literal number.
  • Minimum of trades: 10 on training, 10 on the sealed period. Four of the seven example scripts ended as "not enough trades" on 1D on 6 November 2026.
  • One sealed window: the last 20%, once. One period, one asset, one timeframe. It says nothing about the next period.
  • Not TradingView: it is our own engine, run in your browser. On 1 November 2026, on BINANCE:BTCUSDT 1D, 8 scripts covering the four execution models matched TradingView on 2,433 of 2,433 closed trades for dates, and 2,418 for prices. A measurement on those scripts, not a guarantee for every Pine.
  • One script as it is: no variant search. To search variants and count every trial, use the free Strategy Arena Lab for Windows and Linux.

How the statistics work (SPA test, deflated Sharpe, trial counting) is described in the methodology. For a comparison of out-of-sample tools, see testing a Pine script out of sample, tools compared.

To write or edit Pine you need a TradingView account. Open TradingView (partner link: an eligible subscription may earn us a commission; the free plan is enough to write a script).

FAQ

How do I test a Pine Script strategy out of sample for free?

Paste the Pine v5 script into Strategy Arena's online judge and choose BTCUSDT or load your own candles as a CSV file. The judge replays the script on the first 80% of the bars, keeps the last 20% sealed, and gives its verdict on that sealed period. It runs in your browser, with no account and no install.

Why does my TradingView strategy work in the backtest and fail live?

A common cause is that the rules and settings were chosen on the same history that produced the report, so the result partly describes that history's noise. Testing the unchanged script on a period kept apart from the start shows whether the result survives outside the data it was tuned on. It is a check on past data, not a forecast of live trading.

Can I use my own data instead of BTCUSDT?

Yes. Load a CSV file with time, open, high, low, close and volume columns, from a source whose terms allow your own backtest, for example Binance Vision. The file is read in your browser and never sent. The judge needs at least 300 candles.

What does the mirage verdict mean?

The script lost money on the sealed period, or its training result does not resist the deflated Sharpe check (below 50%). The judge stops there, and the "Where the strategy falls" panel shows the exact rule in red.

What should I do after a "not enough trades" verdict?

Read it as "no conclusion", not as a failure. The sealed period needs at least 10 trades, and the training part needs at least 10 before the seal is opened. A longer history or a shorter timeframe can give more trades; changing the rules to get more trades makes it a new script.

Is the judge the same as TradingView's Strategy Tester?

No. It is Strategy Arena's own engine, compiled to WebAssembly, which follows the script's execution settings. On 1 November 2026 it matched TradingView on 2,433 of 2,433 closed trades for 8 scripts on BINANCE:BTCUSDT 1D. That is a measurement on those scripts, not a guarantee for every Pine.

Next step

Research on past data, not advice. Past results do not guarantee future results.

Revision note, 6 November 2026: first version. The MACD figures come from the judge running the Lab 256 engine on BTCUSDT data up to 16 October 2026; the Binance Vision steps were checked the same day on the September 2026 BTCUSDT 1h and 1D files.

⚠️ 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. Paid options only keep or expand the work — they never change the verdict.

Get the Lab (free) Builder / Operator 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