Test a Pine Strategy Out of Sample for Free (TradingView Basic)
To test a Pine strategy out of sample for free, fix a cut-off date before tuning anything, tune your parameters only on the bars before it, then judge the strategy once on the bars after it. A TradingView Basic account is enough: you just add a period switch to the script.
Updated 17 October 2026. Research on past data, not investment advice.
Why it matters
A result obtained on the bars used for tuning is a training score. The gap can be huge: a strategy found by our GPU made +172.7% on its training data and −37% on unseen data (post-mortem); Turtle 20/10 on EUR/USD went from +31.9% to −42.1% (details).
The script: a switch between tuning and test
Paste this template into the Pine Editor and replace the example rule with yours:
//@version=5
strategy("Out of sample test", overlay=true,
initial_capital=10000,
commission_type=strategy.commission.percent,
commission_value=0.1)
// 1. Cut-off date: set it BEFORE any tuning, then never touch it
cutoff = input.time(timestamp("2024-01-01T00:00:00"), "Start of the test period")
testMode = input.bool(false, "Judge the test period (once only)")
active = testMode ? time >= cutoff : time < cutoff
// 2. Your rule (example: moving-average crossover)
fast = ta.ema(close, input.int(20, "Fast EMA"))
slow = ta.ema(close, input.int(50, "Slow EMA"))
if active and ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
// 3. Outside the active period: no position
if not active
strategy.close_all()
The averages are computed over the whole history (no warm-up gap); only positions are limited to the active period.
The procedure in 5 steps
- Choose the cut-off before looking at a single result. For example, the last 30% of bars (the Lab's default).
- Tune in training mode (
testModeunchecked). Write down every combination you try: that is your number of trials. - Freeze the parameters. Write them down, with the date.
- Tick
testModeonce and read the report: net profit, number of trades, max drawdown, buy-and-hold comparison. - Accept the verdict. If you change a parameter after seeing the test, the test period becomes a training period. You need a new one.
How much history does the free plan give?
TradingView's official comparison, accessed 17 October 2026, lists 5,000 historical bars for Basic. By arithmetic, that is:
| Timeframe | 5,000 bars ≈ | 30% cut-off: test period ≈ |
|---|---|---|
| 1 hour | 208 days | 62 days |
| 4 hours | 833 days (≈ 2.3 years) | 250 days |
| 1 day | 13.7 years (more than BTC history on most venues) | the whole end of the history |
On 1-hour bars the test period may contain few trades. The Lab's judge requires at least 30 independent events before a verdict; below that the test is "inconclusive". Plan limits are detailed in which TradingView plan for backtesting.
Three traps of the manual test
- Looking before cutting. If you have already seen the 2024 chart, your "intuitive" rule takes it into account.
- Opening the test several times. Every opening followed by a tweak turns the test into training. In the Lab, a backtest that overlaps the sealed period gets the
band_already_openedwarning, with the safe range to explore. - Not counting trials. The best of 50 trials on the training period is optimistic by construction; even a good single test should be read with that number in mind (overfitting: 6 tests).
The same test, automated and sealed
The Strategy Arena Lab runs this protocol without self-discipline: it seals the end of the data before any calculation (seal written to disk), counts every trial, shows only training during the search, then opens the sealed period once in front of the judge (walk-forward, deflated Sharpe, SPA test against buy-and-hold). Across 350 automatic research sessions run on pure noise, this protocol returned 0 "holds" (measurement).
- Download the free Lab for Windows: your strategy, your machine, a sealed period.
- Test your Pine strategy for free with the Quick Check, no install.
- Check the trades in TradingView: paste the template above or the Lab's Pine export. Open TradingView (partner link); the free plan is enough.
FAQ
What is an out-of-sample test?
Judging a strategy on data used neither to design nor to tune it. It is the only part of a backtest that resembles the future.
Is paper trading an out-of-sample test?
Yes, strictly: the data is new. But it takes months to gather enough trades. A held-out period gives a first answer right away.
Can you do walk-forward in TradingView?
By hand, moving the cut-off and re-tuning at each fold. It is slow and easy to bias; the Lab does it by blocks automatically.
Do I need TradingView Premium to test out of sample?
No. Deep Backtesting (Premium and higher plans, according to TradingView's help) gives more history and a date range, but the template above works on Basic.
Sources
- TradingView, pricing page (5,000 historical bars on Basic), accessed 17 October 2026.
- TradingView help, "How Deep Backtesting works" (Premium and higher plans), accessed 17 October 2026.
- Strategy Arena: 350 sessions on noise, 1,306 variants, +172% then −37%.
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. Past results do not guarantee future results.
⚠️ 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.