TradingView Backtest & Robustness Lab

Walk-Forward Analysis and Out-of-Sample Testing Guide

Walk-Forward Analysis & Out-of-Sample Testing Guide | SG Group

Backtest Learning ・ BT06

Walk-Forward Analysis and Out-of-Sample Testing Guide

Optimized strategies fall apart in live trading when a good fit to the training period is mistaken for genuine performance. By splitting training and evaluation periods in time order and repeating a frozen-parameter, out-of-sample evaluation through time, you make the signs of overfitting far easier to spot.

  • The difference between OOS and walk-forward, and why random splits leak in time series
  • Single holdout, rolling and anchored designs, with their trade-offs
  • How to reason about window length, update frequency and minimum trade count
  • Reading degradation, stability and distribution together instead of one score
About 12 min read Updated 13 July 2026 For intermediate/advanced traders and Pine developers

Key takeaways

  • Out-of-sample (OOS) evaluates a frozen rule set on a later period that was never used for optimization.
  • Walk-forward repeats “train, freeze parameters, test the next period” through time.
  • In time-series data, random splits invite look-ahead leakage, so you split in chronological order.
  • Rolling and anchored serve different purposes; read degradation, trade count and distribution together.
  • Even walk-forward does not guarantee the future, so pair it with forward testing and stress checks.
On this page

This guide walks through how to design walk-forward analysis and out-of-sample testing so a strategy optimized in TradingView or elsewhere is validated in a way that resembles live trading. We start with the direct answer, then clarify the terminology, the three split designs, window design, how to read the results, leakage defenses, and finally a planner you can run on your own numbers. If you want the fundamentals first, the complete TradingView backtesting workflow makes it easier to place this article in context.

The answer in 30 seconds

Out-of-sample testing means evaluating a frozen rule set on a later period that was never used to optimize the parameters. Strong results on the training period, the in-sample (IS) data, may simply reflect a fit that happened to work in that stretch. So you run the same rules, unchanged, over a period you have not touched, the out-of-sample (OOS) data, and observe how much performance drops. The smaller the fall, the more likely, in relative terms, that the edge is not just a product of curve fitting.

Walk-forward analysis takes that single “train, freeze, then test the next period” procedure and repeats it while advancing through time step by step. Because it evaluates across several regimes rather than one, it lets you check whether the conclusion depends on a single lucky window. As we discuss below, though, this is a technique that makes overfitting easier to see; it does not guarantee future profits.

IS, validation, OOS and forward testing

Let us settle the vocabulary first. Confusing these terms leads to the classic accident of re-running optimization while believing you are validating.

  • IS (in-sample): the training period used to search for and optimize parameters. Its result is close to an upper bound on the fit and should not be read as real-world skill.
  • Validation: an intermediate slice carved out of the in-sample data to compare candidate models. Because it is used to tune model selection, it is not strictly a complete out-of-sample set.
  • OOS (out-of-sample): a period used for neither optimization nor model selection. It is for evaluation only, and the core discipline is never changing the rules after seeing its result.
  • Forward testing: validation that runs forward against future price action in conditions close to live trading. It is more realistic than historical OOS but takes time. For the basics, see TradingView’s official explanation.

Why random splits leak in time series

In general machine learning, you split data randomly into training and validation sets. But doing that on market-like time-series data risks letting future bars bleed into the training side. Trends and volatility are continuous over time, so selecting parameters while future information is present is the same as peeking at the answers to the evaluation period in advance, a look-ahead leak. That is exactly why the split must be chronological, using only the period after the training window for evaluation. For how to read the metrics themselves, our guide on reading backtest results goes into detail.

Single IS/OOS split timeline The whole period is split in time order, with the first part as in-sample (training and optimization) and the later part as out-of-sample (evaluation only). All figures are fictional educational data. Single split: train and evaluate in time order (fictional educational data) 2020-01 2023-12 2024-12 IS (train / optimize) 48 months PF 1.80 / search parameters here OOS 12 months PF 1.30 / frozen for evaluation nothing after this point is used for training
Figure 1: single-split timeline. The first 48 months are optimized (PF 1.80), the later 12 months are evaluated with frozen rules (PF 1.30). All numbers are fictional educational data, not real performance or recommended values.

Three split designs (holdout, rolling, anchored)

Walk-forward splitting takes three main forms. Choose by purpose, and where possible run several side by side to confirm the conclusion does not swing.

1. Single holdout split

The simplest method divides the whole period just once into “first part = IS / later part = OOS” (Figure 1). It quickly gives a first read on overfitting, but because the evaluation depends on a single regime, the conclusion is biased if that period happened to be a tailwind or a headwind.

2. Rolling walk-forward

This keeps the training window a fixed length and slides the whole window forward. Because old data drops out of training, it suits checking how closely the strategy tracks recent regimes. On the other hand, distant history is not fully used, so long-term stability is harder to see.

3. Anchored walk-forward

This fixes the start point of the training window and extends it further with each step forward. It suits using as much data as possible and judging long-term stability from accumulated information. However, its reaction to recent changes tends to be slower than rolling.

Comparison of rolling and anchored walk-forward windows The top row shows rolling (fixed-length training window moving forward); the bottom row shows anchored (fixed start point with an extending training window). In both, the evaluation window sits immediately after the training window. All figures are fictional educational data. Rolling (fixed-length training window) TrainTest Fold 1 → advance Anchored (fixed start, training window extends) start fixed → extend
Figure 2: the top row (rolling) keeps the training-window length and advances; the bottom row (anchored) fixes the left edge and extends the training window. In both, the evaluation window (darker outline) sits immediately after the training window, and no optimization happens during evaluation. This is a schematic; the figures are fictional educational data.
Table 1: comparison of the three split designs (conceptual, based on fictional educational data)
DesignTraining windowBest suited toWatch out for
Single holdoutOne split onlyA quick first readEvaluation depends on one regime
RollingFixed length, moves forwardTracking recent regimesDistant history not fully used
AnchoredFixed start, extendsLong-term stabilitySlower to react to recent change

Window length and update frequency

Once the split design is chosen, the next step is to set the concrete lengths and frequency. There is no universal golden ratio here; you work backwards from the nature of the strategy.

  • Training-window length: longer tends to make rules more stable but slower to react to recent change. Secure a length that at least includes the market regimes you want covered (uptrend, downtrend, range).
  • Evaluation-window length and step: a short evaluation window leaves too few trades and the numbers become noisy. Setting the step equal to the evaluation window keeps evaluation periods from overlapping, so they read as independent segments.
  • Minimum trade count: decide in advance the floor for how many trades you want in each evaluation window. Windows below it are treated as reference only, not as the basis for conclusions.
  • Regime: check whether you are spanning periods where rates, volatility and liquidity change materially. An outside view such as the Macro Research Workbench can help you map market regimes.

From here on, this article uses a consistent illustration: 18 training months, 6 evaluation months, a 6-month step and a 72-month total period. This is fictional educational data for explanation, not a recommended ratio.

The per-fold procedure and its cardinal rule

In each fold (one training-plus-evaluation unit), follow this order strictly. Break the order and the validation no longer holds.

  1. Train: search parameter candidates using only that training window.
  2. Select: narrow to one set using a pre-decided criterion (for example, choosing a stable region).
  3. Freeze: lock the chosen parameters and do not touch them afterwards.
  4. Evaluate: run the frozen rules as-is over the immediately following evaluation window and record the result.
  5. Advance: move the windows forward by the step and proceed to the next fold.

The single most important rule here is to never re-pick parameters after seeing the evaluation window’s result. If you adjust after seeing it, that period has now been used in optimization and is no longer out of sample. “Keep tuning while watching OOS until good numbers appear” is not validation; it is time-shifted optimization. If you truly must adjust, reserve a fresh period you have never looked at and use it for evaluation. The pitfalls of parameter search themselves are explored in how to detect backtest overfitting with parameter stability.

Reading out-of-sample results

Once you have gathered per-fold evaluations, do not decide good or bad from a single score; read several perspectives side by side. The following is fictional educational data run under the setup described above (18 training months, 6 evaluation months).

Table 2: per-fold OOS results (fictional educational data, six folds)
FoldEvaluation periodIS PFOOS PFWFE (net-profit ratio)OOS tradesOOS max DDStatus
F12020 H21.821.4461%64-7.8%Fairly stable
F22021 H11.751.5168%59-6.9%Fairly stable
F32021 H21.931.1234%48-12.4%Large degradation
F42022 H11.701.3355%53-9.6%Middle
F52022 H21.861.0829%44-13.1%Large degradation
F62023 H11.781.3958%57-8.3%Fairly stable

In this example, the average walk-forward efficiency (WFE) across the six folds is about 51%, meaning roughly half of the in-sample edge is lost over the evaluation periods. What stands out is F3 and F5, where WFE falls to around 30% and the maximum drawdown is also deeper than the rest. Both fall in periods where market volatility shifted, hinting that the rules work less well in specific regimes. Rather than glancing at the average and calling it “fine,” it matters to read individually which fold broke down, and why. For a deeper look at drawdown, see maximum drawdown explained.

Per-fold IS vs OOS profit factor comparison For six folds, paired bars show the profit factor of the training period (IS) and the evaluation period (OOS). The band marks the amount of degradation. F3 and F5 degrade the most. All figures are fictional educational data. IS vs OOS profit factor (fictional educational data) 2.0 1.0 0 F1 F2 F3 F4 F5 F6 IS PF OOS PF large-degradation fold
Figure 3: per-fold IS vs OOS profit factor. Dark navy is IS, brown is OOS, and the red band marks folds with large degradation (F3 and F5). Meaning is conveyed by labels and the band in addition to color. All numbers are fictional educational data.

Avoiding leakage and look-ahead bias

The reliability of walk-forward hinges on whether you have prevented leakage. Here are the common pitfalls.

  • Look-ahead: using the close of a bar that has not yet completed, or an indicator that is only known later, in the calculation.
  • Overlapping periods: the training and evaluation windows overlap in time, so the same bars fall into both.
  • Repeated trials on the same data: testing many times on the same OOS period lets fitting creep into that period too.
  • Regime imbalance: the evaluation period is skewed toward a particular market regime, hiding behavior in other regimes.

One defense is to place an embargo (buffer period) between the training and evaluation windows. When the lookback needed for an indicator straddles the boundary, information can leak near the edge. Inserting a gap of a few bars suppresses training information from seeping into the entrance of the evaluation window.

Comparison of leaky and leakage-resistant splits The top row is a bad example where the training and evaluation windows overlap and leakage occurs. The bottom row is a good example split in time order with an embargo inserted. All figures are fictional educational data. Bad split: overlapping windows invite look-ahead Training window Evaluation window (overlaps) overlap = leak source Good split: chronological + embargo isolation Training window buffer Evaluation window (no overlap)
Figure 4: the top row is a bad example where the training and evaluation windows overlap and leakage occurs; the bottom row is a good example split in time order with an embargo (buffer period) inserted. Removing the overlap isolates the evaluation window from the influence of training. This is a schematic and the numbers are fictional educational data.

Try the window planner

Enter the total period, training months, evaluation months and step months, and the folds are drawn on an illustrative timeline. Values are computed inside your browser only; no dates or personal data are sent anywhere. If JavaScript is disabled, see the static calculation example directly below.

Static calculation example (when JavaScript is off): with a total of 72 months, 18 training months, 6 evaluation months and a 6-month step, the first training window is months 1–18 and the first evaluation window is months 19–24. From there it advances 6 months at a time, and as long as the evaluation window does not run past the end of the total period, you can build 10 folds in total (the evaluation-window tail reaches at most month 72). A rough count of folds is “(total − training − evaluation) ÷ step + 1”.

Walk-forward window planner

Length of the whole backtest period
Length of the window used for optimization
Window where frozen rules are evaluated
How far each fold advances

Press “Calculate the split” with the values above to show the number of folds and each window.

    This planner is for illustrating the logic; it does not calculate performance or profit. Tune your actual fold design while watching trade counts and the distribution of regimes.

    No future guarantee: the link to forward testing

    Even if OOS degradation is small in walk-forward, that only shows the rules were “not purely a fit in any of the past regimes.” There is no guarantee the future market keeps the same character as the past. In particular, if a regime that has never appeared before arrives, the premise itself breaks down.

    So after historical walk-forward, connect to forward testing in conditions close to live trading. Running forward with fills, spread and slippage included surfaces frictions that desk-level OOS cannot see. How to reflect costs is covered in modeling slippage, spread and fees, and behavior when several strategies are bundled together is covered in multi-strategy portfolio backtesting. Rather than treating one validation as “done,” shaking the premise from several angles is a realistic defense against overfitting.

    Practical checklist

    • Is the split chronological? Has a random split let look-ahead leakage slip in?
    • In each fold, is the “train, freeze, evaluate” order kept, without adjusting after seeing the evaluation result?
    • Does each evaluation window meet the minimum trade count? Are you basing conclusions on windows with too few trades?
    • Have you checked that the conclusion does not swing across several designs, such as rolling and anchored?
    • Are you reading WFE, degradation, trade count, drawdown and distribution together rather than relying on one score?
    • Have you checked for overlap between training and evaluation windows and whether an embargo is needed?
    • After walk-forward, have you connected to stress tests that vary costs and regimes, and to forward testing?

    Frequently asked questions

    What is out-of-sample testing?
    Out-of-sample testing evaluates the performance of a frozen rule set on a later period that was never used for optimization. You split the data in time order into the training period (in-sample) and the evaluation period (out-of-sample), and you never touch the parameters during the evaluation window. The goal is to check whether strong in-sample results are just a coincidental fit, so you read degradation, trade count and distribution together rather than relying on a single metric.
    What IS/OOS split ratio should I use?
    There is no universally optimal ratio. A longer training window tends to make rules more stable but leaves less out-of-sample data, while a shorter one reduces the statistical margin of the evaluation. Work backwards from the strategy’s holding period, trade frequency and the number of market regimes you want to cover, and decide based on whether each evaluation window keeps enough trades. The article uses 18 training months and 6 evaluation months as an illustration, but that is for explanation, not a recommended value.
    Is rolling or anchored walk-forward better?
    It depends on your purpose. Rolling keeps the training window a fixed length as it moves forward, so it suits checking how closely the strategy tracks recent regimes. Anchored fixes the start point and extends the training window, so it suits using as much data as possible to judge long-term stability. There is no general answer as to which is superior, and a practical approach is to run both side by side and confirm the conclusion does not swing.
    Can I change parameters after seeing OOS results?
    Once you adjust parameters after seeing the evaluation results, that period is no longer out of sample. As soon as you use an evaluation result even once for optimization, you have effectively folded it into the training period and lost the ability to detect degradation. If you want to adjust, reserve a fresh period you have never looked at and evaluate the frozen rules there again.
    What is walk-forward efficiency?
    Walk-forward efficiency (WFE) is a relative value that divides the evaluation-period result by the training-period result to roughly gauge the degree of overfitting. The smaller the value, the more of the in-sample edge is lost in live-like conditions. However, it becomes unstable when the trade count is low, and it is not a metric that decides pass or fail on its own. Read it together with degradation, trade count, drawdown and distribution.
    How should I handle folds with too few trades?
    Numbers from an evaluation period with few trades are heavily influenced by chance, so avoid using them directly in your conclusion. Decide a minimum trade-count threshold in advance, and either treat windows below it as reference only or lengthen the evaluation window to secure more trades. When only a few periods look extremely good or bad, check individually whether they are being dragged by that period’s market regime or by a single outlier trade.
    Is Deep Backtesting the same as out-of-sample testing?
    No, they are not the same. Deep Backtesting refers to an execution feature that runs a backtest over a longer period or on finer bars. Out-of-sample testing is a design concept about which period you train on and which period you evaluate on. Being able to run a long period and being able to isolate the evaluation period from optimization are separate problems, so do not confuse the two.
    Can walk-forward analysis eliminate overfitting?
    No, it cannot eliminate it completely. Walk-forward analysis is a technique that makes signs of overfitting easier to spot; it does not guarantee future performance. If you repeat trials on the same data, fitting creeps into the evaluation periods too, and if the market regime changes from the past, the premise breaks down. Combine it with forward testing in live-like conditions and stress checks that vary costs and regimes.
    Disclaimer: This article and the tool provide descriptive aggregation, diagnostics and visualization of loaded backtest data as educational and informational content. They are not investment advice, a buy/sell signal, a forecast of future prices or a guarantee of profit. All numbers and figures shown are fictional educational data and do not represent real performance or recommended parameters. Backtest results do not guarantee future performance and change with assumptions, data, costs and market regime. Final decisions are your own responsibility. TradingView interface names and specifications may change, so please check the official pages for the latest information. We do not claim any partnership or endorsement relationship with TradingView.