How to run an out-of-sample test on a TradingView strategy
TradingView’s Strategy Tester has no built-in out-of-sample split: it reports one run over the chart’s date range, usually the same history the settings were tuned on. To test out of sample, pick a cut date before tuning (typically keeping the most recent 20% to 30% aside), tune only on the trades before it, freeze the settings with real fees, then compare the trades after the cut with the trades before and with simply holding the asset.
No CSV at hand? Try the preview on the example export (1 click) →
Why a full-history backtest is not enough
When the parameters are chosen on the same bars as the result, the result describes the tuning as much as the rule. The more settings you try, the better the best one looks, partly by chance. Only a period that played no part in the choice tells whether the rule holds outside the bars it was fitted on. The Strategy Tester does not keep such a period aside for you: you have to set it yourself, before tuning.
The out-of-sample test, step by step
- Pick the cut date first: Before changing any setting, choose the date that splits the history in two and write it down. Keep the most recent part aside, typically the last 20% to 30% of the period: the free judge seals the last 20% of the candles, the dossier the most recent 30% of the period when you give no date.
- Tune only on the period before: Choose the parameters while looking only at the trades entered before the cut date: limit the backtest date range so that it ends at the cut date, or read only those rows of the List of trades. Note how many settings you try.
- Freeze the settings and set real fees: Put your broker’s real commission and slippage in the strategy properties, then stop: no parameter changes after this point, whatever the later period shows.
- Run the whole history and export the List of trades: Run the frozen strategy on the full date range, open the List of trades tab of the Strategy Tester and export the CSV. Every trade entered on or after the cut date belongs to the out-of-sample part.
- Compare before and after, against holding: For each part, compare the compounded result, the average trade, the number of trades and the maximum drawdown, then the return of simply holding the asset over the same dates (last close divided by first close, minus 1). Then add extra fees per order and see what is left.
Steps 4 and 5 are what the free dossier preview does on your export: give it the cut date and it shows the compounded result before and after, and the whole period with extra fees. Free preview →
A simple walk-forward on TradingView
A walk-forward repeats the out-of-sample test on windows that move forward in time, so the result does not rest on a single cut date.
- Split the history into consecutive windows, for example one year each.
- Tune on the first windows only (say years 1 and 2), freeze, and note the result of year 3 without changing anything.
- Move forward: tune again on the data up to the end of year 3, freeze, and note year 4. Repeat to the end of the history.
- Put the noted windows end to end: that chain, and only it, is the walk-forward result. Compare it with holding the asset over the same windows, fees included.
Each new tuning gives other parameters, hence another List of trades: export one CSV per window and read only the trades of the window you noted. Running the preview several times with different cut dates on one frozen strategy is a different check: the same settings tested on several later periods. It is useful too, as long as the settings were chosen before the earliest cut date.
A worked example, with exact figures
Synthetic data. 69 generated trades (2021-02-03 → 2025-03-27; moving-average crossover, long only, 0.1% commission per order), not a real account or market. The calculation is the one of a real dossier.
Read on the whole period, this rule shows +89.22%. Split at 2023-12-29 (the default cut: the most recent 30% of the period), the part where it was tuned gives +108.51% over 47 trades, against +80.45% for holding the asset. The part it had not seen gives −9.25% over 22 trades, against −13.85% for holding. After the cut the rule lost less than holding, and its average trade went from +2.00% to −0.30%. Maximum drawdown: 33.92% before the cut, 25.58% after. With 0.10% extra fees per order, the whole period goes from +89.22% to +64.95%.
What you gain: before risking money, you see which part of the result comes from the period the rule was tuned on, and what it kept on the period it had not seen.
Pitfalls that empty an out-of-sample test of its meaning
- Re-optimising after seeing the test period. Once a parameter changes because of what the later period showed, that period has become part of the tuning and no longer tests anything. Count it as a new try; a period that is untouched again only comes with new data.
- Moving the cut date until the result looks good. Trying cut dates one after another is tuning on the cut date. Fix it before looking, and count every variant you try: the more there are, the more a good result can come from chance.
- Too few trades after the cut. Five trades can land on either side of zero by luck. Aim for at least 10 after the cut date; the judge and the dossier both ask for that.
- Repaint and future data. A script that reads a higher timeframe with
request.securityandlookahead_onwithout a one-bar offset uses closes that did not exist yet, before and after the cut alike. See step 4 of the indicator-to-strategy guide. - Zero fees. A rule that trades often can keep its edge before the cut and lose it after once each order pays. Set real costs before the test; the fee calculator shows what they do to a result.
Two free tools that make the split for you
The free judge, for a Pine strategy
Paste a Pine strategy: the judge replays it in your browser on real BTCUSDT candles (1 hour, 4 hours or 1 day). The last 20% of the candles stay sealed, and the verdict rests on that period only, with the script’s fees, against simply holding. A journal kept in your browser lists the versions you have judged, so you see how many tries you made; it does not change the verdict. The free Lab counts every variant in its verdict. No account, and your script is not sent.
The free dossier preview, for any market
Export the List of trades from the Strategy Tester and upload it with your cut date. The free preview shows the compounded result before and after that date, and the whole period with 0.10% extra fees per order; without a date, the most recent 30% of the period is set aside. The full dossier (€9.00, once) adds the drawdown against holding, the Monte Carlo and the result without the best trades. No account and no Pine script needed.
The export button of the List of trades needs a paid TradingView plan; on the free plan, paste your Pine script into the free judge above.
Questions
Does the TradingView Strategy Tester have an out-of-sample test?
Not as a built-in split. The Strategy Tester reports one run over the date range of the chart, usually the same history the settings were chosen on. To test out of sample, you pick a cut date yourself, tune only before it, and read the trades after it separately: by hand, with the free dossier preview on the List of trades export, or with the free judge on a Pine strategy.
How much of the history should I keep out of sample?
Usually the most recent 20% to 30%. The free judge seals the last 20% of the candles; the dossier sets the most recent 30% of the period aside when you give no cut date. The later part must still hold enough trades to say something.
How many trades do I need after the cut date?
At least 10, and more is better. Below 10 trades in the sealed period, the judge reports too little activity to conclude, and the dossier asks for 30 trades in total, 10 of them after the cut, for a clear reading. If you have fewer, use a longer date range or a shorter timeframe.
What is the difference between an out-of-sample test and a walk-forward?
An out-of-sample test uses one cut date: tune before, check after, once. A walk-forward repeats it on rolling windows: tune on a first window, record the next one untouched, move both forward, tune again, and so on. Only the untouched windows, put end to end, count as the result.
Is my CSV or my Pine script sent anywhere?
The judge replays the Pine script in your browser and does not send it. For the dossier, only the CSV is uploaded, never the Pine script; the raw export is not kept: only the computed dossier is stored, 12 months after payment, and an unpaid preview is deleted after 30 days.
See also: Monte Carlo on the List of trades CSV · fee calculator · convert an indicator into a strategy
Research on past data. Strategy Arena gives no investment advice and does not trade for you. Past results do not predict future results. TradingView is a trademark of TradingView, Inc.