TradingView Backtesting

Volatility Clustering on TradingView: Conditional Risk and Regimes

Volatility clustering means large price changes tend to occur near other large changes, while quiet periods tend to persist. The signs can still alternate: persistent return magnitude does not imply a predictable price direction. On a TradingView dataset, inspect consecutive returns and the autocorrelation of their absolute or squared values before choosing a conditional volatility model.

See the decision guide

A quiet, active, quiet sequence with changing signs

Use these 12 hypothetical daily simple returns as a small arithmetic example. The dates are consecutive trading observations, and the percentages describe the same asset on the same sampling basis. The middle four observations have larger magnitudes even though their signs change. Twelve observations illustrate a calculation; they are not enough to establish a reliable market model.

  • Across all 12 observations, the mean signed return is zero and the mean squared decimal return is 0.0044 / 12. Its square root is 1.9149% per observation, which does not reveal where the active interval occurred.
  • Under an explicit zero-mean assumption, a four-observation rolling root mean square is 1% after observation 4, 3% after observation 8 and 1% after observation 12. These are window endpoints, not forecasts made before those windows.
  • The quiet and active labels here were assigned after seeing the sequence. A tradable filter must instead set its threshold in advance and use only observations available at the decision time.
ObservationsReturns in time orderAbsolute returnsDescriptive interval
1 to 4-1%, -1%, -1%, +1%1%, 1%, 1%, 1%Quiet
5 to 8+3%, -3%, -3%, +3%3%, 3%, 3%, 3%Active
9 to 12+1%, +1%, +1%, -1%1%, 1%, 1%, 1%Quiet

Calculate autocorrelation of magnitude, not just returns

Following the NIST sample autocorrelation convention, for a series x with full-sample mean x̄, ACF(k) = Σ from t=k+1 to N of (xₜ - x̄)(xₜ₋ₖ - x̄), divided by Σ from t=1 to N of (xₜ - x̄)². Use the same mean and full denominator at every lag. Apply this separately to r, |r| and r². Scaling the whole series by a constant does not change its ACF.

  • Validate all 12 numeric cells first. Do not let a blank stand in for a missing return. If every magnitude is identical, the ACF denominator is zero and the statistic is undefined.
  • Inspect several preselected lags on a longer sample. A positive magnitude ACF is evidence of dependence in that sample, not proof of a particular GARCH specification or of profitable forecasting.
  • Correlating two truncated columns with a spreadsheet CORREL function uses different means and denominators. It need not reproduce this full-sample ACF convention.
  • Avoid diagnosing clustering from the ACF of overlapping rolling-volatility estimates alone. Adjacent windows share observations and can look persistent for that mechanical reason.
Series, using percentage-point inputsFull-sample meanLag-1 numerator / denominatorACF(1)
Signed returns r0-1 / 44-0.0227
Absolute returns |r|5/3(56/9) / (32/3)0.5833
Squared returns r²11/3(896/9) / (512/3)0.5833
Spreadsheet reproduction for absolute returns; enter the 12 returns as percentages in A2:A13text
B2 = ABS(A2)                 [copy through B13]
E1 = AVERAGE(B2:B13)
C2 = (B2-$E$1)^2             [copy through C13]
D3 = (B3-$E$1)*(B2-$E$1)     [copy through D13]
E2 = IF(SUM(C2:C13)=0,NA(),SUM(D3:D13)/SUM(C2:C13))
Expected E2 = 0.5833333333

Rolling volatility, EWMA volatility and GARCH volatility

Let εₜ be the return after subtracting the specified conditional mean, and hₜ the variance forecast for period t made before its return arrives. For the arithmetic examples, the mean is assumed to be zero. Keep returns in decimals, variance in squared decimals and volatility as the square root of variance.

  • EWMA has no separate long-run variance target. In this recursion it is the ω = 0, α = 1 - λ, β = λ boundary case; it does not have the mean reversion of a finite-variance GARCH model with α + β < 1.
  • A GARCH fit needs more than a visible cluster. Check optimizer convergence, sensitivity to initialization, parameter constraints and standardized residuals εₜ / √hₜ. Remaining dependence in squared standardized residuals means the variance model has left structure unexplained.
  • Choose the estimation window and innovation distribution explicitly. Short samples, heavy tails, changing market structure and asymmetric responses to gains and losses can undermine a basic symmetric GARCH fit. A visually smoother line is not evidence of better forecasts.
MethodCalculation or updateUseful taskRequired choices and limits
Rolling volatilitySample standard deviation of the last n returns, using their window mean and n - 1 denominator.Describe recent dispersion and compare windows.Choose n and a complete sampling calendar. Equal weights drop abruptly when an observation leaves the window. A zero-mean RMS uses n instead and is a different estimator.
EWMAhₜ₊₁ = λhₜ + (1 - λ)εₜ²Update a variance estimate after each observation with declining weights on older shocks.Specify 0 < λ < 1, the mean and initial variance. RiskMetrics used 0.94 for daily data; it is not a universal choice for every asset or bar interval.
GARCH(1,1)hₜ₊₁ = ω + αεₜ² + βhₜEstimate persistence and conditional variance forecasts from a return series.Estimate parameters with a stated likelihood and mean model; require ω > 0, α ≥ 0 and β ≥ 0. Under the usual unit-variance innovation assumptions, α + β < 1 gives finite unconditional variance ω / (1 - α - β).

One 3% shock, two next-period variance forecasts

Assume the prior daily variance is hₜ = 0.0001, equivalent to 1% daily volatility, and the new zero-mean return residual is +0.03. These parameters are illustrative, not fitted to market data. EWMA uses λ = 0.94. GARCH uses ω = 0.000002, α = 0.08 and β = 0.90.

  • A -3% residual produces the same result in both symmetric updates because it is squared. The calculation changes expected magnitude, not the expected sign.
  • For these GARCH parameters, α + β = 0.98 and the unconditional variance is 0.000002 / 0.02 = 0.0001. If α + β reaches 1, that finite long-run variance formula is unavailable; do not divide by zero or report a negative variance when the sum exceeds 1.
  • The new forecasts are available only after observing the 3% move. Using them to size the position that already experienced that move introduces future information into the backtest.
  • Neither forecast bounds the next loss. A gap can exceed several forecast standard deviations, and the innovation distribution matters when converting volatility into a tail-risk estimate.
ModelNext-period variance calculationNext-period volatility
EWMA0.94 × 0.0001 + 0.06 × 0.0009 = 0.000148√0.000148 = 1.2166%
GARCH(1,1)0.000002 + 0.08 × 0.0009 + 0.90 × 0.0001 = 0.000164√0.000164 = 1.2806%

Build a TradingView dataset that can answer the question

TradingView chart-data export provides a price series for this analysis. Its help page says exported data reflects the data loaded on the chart. Save the symbol, exchange, timeframe, session, adjustment settings and date coverage with the CSV. Use standard time-based bars and consecutive, non-overlapping returns.

  • Choose price returns or account returns before calculating. An account return series needs account equity at regular boundaries, including open positions and an explicit treatment of cash flows and costs. Irregular closed-trade percentages are not daily account returns.
  • Use a consistent trading calendar. Identify missing bars, stale prices and split or dividend adjustments before interpreting a large squared return. Do not fill unknown observations with zero.
  • For intraday studies, compare like session intervals or model time-of-day seasonality first. Repeated opening and closing activity can resemble persistent risk when pooled without that adjustment.
  • Fit on an earlier period, freeze the chosen specification, then generate each subsequent forecast with only prior data. Compare held-out variance forecast errors on the same target and sampling basis; preserve the losing comparisons as well.
  • If you define high-risk and low-risk regimes using a percentile threshold, estimate that threshold from training data or a past-only window. Full-history percentiles leak later observations into earlier classifications.

Review strategy results alongside the separate risk study

Backtest Deep Report accepts TradingView List of Trades CSV files and calculates supported results such as net profit and drawdown. Reconcile its imported trades and initial capital with the source backtest. A trade export does not contain the full regular return series needed for the clustering calculation above.

  • Calculate the ACF, EWMA and fitted GARCH diagnostics independently. This page does not claim that Backtest Deep Report provides those statistics or a built-in GARCH estimator.
  • Keep the forecast timestamps with your research data when comparing strategy outcomes in quiet and active periods. A regime label is an explanatory grouping until a separate test establishes whether using it improves a specified strategy.
  • For a custom chart display, Pine Script AI Coding Agent can help draft a statistic from an explicit formula. Specify the mean, lookback, initialization and confirmed-bar behavior, then verify numerical outputs independently. Implementing a recursion with chosen coefficients is not the same as estimating GARCH parameters.
Where Pineify fits

Backtest Deep Report

Review supported profit and drawdown results from a TradingView trade CSV while keeping the regular-return volatility study separate.

Also useful: Pine Script AI Coding Agent. Draft a custom chart statistic with explicit inputs and timing, then compare its values with your independent calculation.

Review exported trades

Frequently asked questions

Educational information, not investment advice. All numerical examples are hypothetical and are not measured strategy performance. Estimated volatility and backtest results do not guarantee future returns or limit possible losses.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.