OPEN-SOURCE SCRIPT
BNS Jump Statistic & RV Decomposition

BNS Jump Statistic & RV Decomposition
A jump-detection oscillator that splits realized variance into a continuous (diffusive) component and a jump component, using the bipower variation framework of Barndorff-Nielsen and Shephard. It answers a specific question: how much of recent volatility is everyday noise, and how much is sudden, discontinuous moves?
How it works
Over a rolling window of length N, three quantities are computed from log returns:
The Relative Jump (RJ) ratio is J / RV — the share of variance attributable to jumps. Bounded between 0 and 1: zero means all-continuous, one means all-jump.
The BNS z-statistic (ratio form, with the Huang–Tauchen adjustment) tests whether the jump component is statistically significant. It uses tripower quarticity for a robust standard error:
Pine Script®
Under the null of no jumps, z is asymptotically standard normal. Critical values at 1.96, 2.58, and 3.09 correspond to 95%, 99%, and 99.9% confidence.
How to read it
Inputs
Built-in alerts
All alerts fire on the rising edge of their event — one notification per transition rather than one per bar while the condition holds.
Notes
The decomposition is a property of the chosen window. Different lengths give different splits; shorter windows are more responsive but noisier. The z-statistic is asymptotic, so very short windows can produce inflated values — treat anything below N=10 with care.
Bipower variation is robust to jumps in theory but sensitive to microstructure noise on very fine timeframes. Daily and 5-minute-and-up tend to behave well.
This is a diagnostic tool, not a signal generator. It tells you when variance is being driven by jumps rather than diffusion.
Five years of work on a trading system left me with dozens of indicators that ultimately didn't earn a place in the final build. They're not failures — they're tools that solved problems I no longer needed solved. So instead of shelving them, I'm publishing the majority of them open-source.
If you're a discretionary trader, take what's useful. If you're a systems builder, the source is yours to dissect, modify, and improve. The best return on five years of work is for it to keep working — for someone.
If you use this script — or part of it — in your own work, please credit the original with a link back to my profile.
Note: these indicators have been updated to Pine Script v6 — some manually, some with AI assistance.
A jump-detection oscillator that splits realized variance into a continuous (diffusive) component and a jump component, using the bipower variation framework of Barndorff-Nielsen and Shephard. It answers a specific question: how much of recent volatility is everyday noise, and how much is sudden, discontinuous moves?
How it works
Over a rolling window of length N, three quantities are computed from log returns:
- Realized Variance (RV) — the sum of squared returns. Captures everything: continuous variance plus any jumps.
- Bipower Variation (BV) — the (π/2)-scaled sum of |r_t|·|r_{t−1}|. Asymptotically robust to jumps, so it captures only the continuous part.
- Jump component (J) — max(RV − BV, 0), the variance left over after subtracting the continuous estimate.
The Relative Jump (RJ) ratio is J / RV — the share of variance attributable to jumps. Bounded between 0 and 1: zero means all-continuous, one means all-jump.
The BNS z-statistic (ratio form, with the Huang–Tauchen adjustment) tests whether the jump component is statistically significant. It uses tripower quarticity for a robust standard error:
Under the null of no jumps, z is asymptotically standard normal. Critical values at 1.96, 2.58, and 3.09 correspond to 95%, 99%, and 99.9% confidence.
How to read it
- Columns show the RJ ratio. Cool cyan when variance is mostly continuous; amber and rose as the jump share rises.
- Smoothed line is a 3-bar EMA of RJ, layered with a soft glow. The line color tracks the regime — useful for spotting persistent jump activity versus one-off spikes.
- Reference levels at 20%, 50%, and 80% mark the continuous threshold, the regime boundary, and the extreme zone.
- Markers above the pane fire on bars where the BNS test is significant: a circle at 95%, a triangle at 99%, a diamond at 99.9%.
- Background tint reflects the regime state (CONTINUOUS, MIXED, or JUMP), with hysteresis so it doesn't flicker on borderline bars.
- Status table in the top-right shows the latest RV, BV, jump component, RJ, z-statistic, and current significance level.
Inputs
- Window Length — bars used to compute RV and BV. 22 ≈ one trading month on daily. Default 22.
- Source — input series. Default close.
- Significance thresholds — z-values for 95%, 99%, and 99.9% confidence. Defaults 1.96, 2.58, 3.09.
- Regime thresholds — RJ levels marking the continuous and jump regimes. Defaults 0.20 and 0.50.
- Display toggles — status table, regime tint, significance markers, and reference levels.
Built-in alerts
- Significant Jump (95%) — z crosses above 1.96
- Strong Jump (99%) — z crosses above 2.58
- Extreme Jump (99.9%) — z crosses above 3.09
- Entered Jump Regime
- Returned to Continuous Regime
All alerts fire on the rising edge of their event — one notification per transition rather than one per bar while the condition holds.
Notes
The decomposition is a property of the chosen window. Different lengths give different splits; shorter windows are more responsive but noisier. The z-statistic is asymptotic, so very short windows can produce inflated values — treat anything below N=10 with care.
Bipower variation is robust to jumps in theory but sensitive to microstructure noise on very fine timeframes. Daily and 5-minute-and-up tend to behave well.
This is a diagnostic tool, not a signal generator. It tells you when variance is being driven by jumps rather than diffusion.
Five years of work on a trading system left me with dozens of indicators that ultimately didn't earn a place in the final build. They're not failures — they're tools that solved problems I no longer needed solved. So instead of shelving them, I'm publishing the majority of them open-source.
If you're a discretionary trader, take what's useful. If you're a systems builder, the source is yours to dissect, modify, and improve. The best return on five years of work is for it to keep working — for someone.
If you use this script — or part of it — in your own work, please credit the original with a link back to my profile.
Note: these indicators have been updated to Pine Script v6 — some manually, some with AI assistance.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.