OPEN-SOURCE SCRIPT
Güncellendi Volatility Bands IV-RV

The question this answers
Every expected-move indicator draws the range options are pricing. Almost none of them tell you whether that range is any good. This one measures the implied range and the realized range side by side, then counts how often price actually finished outside each of them.
Three layers
The cones. Two ranges are drawn across history, both anchored one horizon back and re-anchored every week. The amber cone is built from implied volatility, read from India VIX. The cyan cone is built from realized volatility, measured on weekly bars of the chart symbol. Both are scaled to the same horizon with the same geometry, so a difference in width is a difference in volatility and nothing else.
Shading is nested rather than overlapping. The neutral core is the range both measures agree on. The band outside it is the gap between them, coloured by whichever cone sits on the outside. That gap is the variance risk premium made visible, and when it changes colour, realized has overtaken implied.
The breach layer. Every bar that closes outside a cone is shaded. On its own this means very little, and that is the point most published expected-move scripts miss. A one-sigma cone is breached about 31.7 percent of the time by construction. So the readout states the expected rate next to the rate actually observed on your loaded history, for both cones separately.
If the implied cone is breached far less often than expected, implied volatility was systematically wider than the index needed. If it is breached more often, it was too narrow. That comparison is evidence. The shading alone is not.
The forward cone. From the current bar, projecting one horizon ahead, using the latest confirmed weekly volatility. Same nested construction. It is a distribution, not a direction.
How it is calculated
Implied leg. India VIX is an annualised implied volatility in percentage points, rescaled to the horizon by the square root of the horizon over 52.
Realized leg. Weekly log returns over the lookback, scaled to the horizon by the square root of the number of weeks. Three estimators:
Yang-Zhang, the default. Weekend-gap variance, open-to-close variance and the Rogers-Satchell range term, weighted by the standard k factor. It uses the whole weekly bar and is the most efficient and most drift-independent.
Std Dev. Sample standard deviation of weekly close-to-close log returns. Blind to everything inside the week.
ATR%. Weekly Average True Range as a fraction of price, times a factor you set. Range-aware, but the factor is a convention.
Bands are lognormal by default. That is not cosmetic: under a zero-drift random walk the expected breach rate of a lognormal band is exactly 2(1 - Phi(k)), so the observed-versus-expected comparison is exact rather than approximate.
Timeframes
All volatility maths runs in the weekly context, so the readings are identical on a 15-minute chart and on a weekly chart. Use any timeframe up to Weekly. Above Weekly the indicator disables itself and says why, because a weekly request from a monthly chart returns partial bars.
Alerts
Six: the implied-to-realized ratio crossing either threshold, and price closing outside either cone in either direction.
Limitations, stated plainly
India VIX measures implied volatility on NIFTY 50. The implied source is an input so you can pair another index with its own volatility index, not so you can run this on any symbol. Pairing one instrument's implied volatility with another's realized volatility is meaningless.
The breach sample counts weeks, not independent trials. Consecutive windows overlap by all but one week, so divide n by the horizon for a rough independent count and do not read small differences as significant.
The realized cone is estimated from the same series it is tested against, so its observed breach rate is not an out-of-sample result. The implied cone does not have this problem, which is part of why the two are reported apart.
Counting starts at the left edge of your loaded history, which varies by subscription and timeframe. Two users can see different n on the same symbol.
Square-root-of-time scaling assumes weekly returns are independent. Real index returns cluster in volatility, so it understates the tails in a stress regime and overstates them coming out of one.
The implied leg uses a single at-the-money volatility number and ignores skew, so it understates downside and overstates upside against the real option surface.
One sigma is a description of a distribution, not a boundary. Cones being broken is expected behaviour.
This plots volatility. It produces no directional signal, no entries and no exits.
Not financial advice. For education and research only.
Every expected-move indicator draws the range options are pricing. Almost none of them tell you whether that range is any good. This one measures the implied range and the realized range side by side, then counts how often price actually finished outside each of them.
Three layers
The cones. Two ranges are drawn across history, both anchored one horizon back and re-anchored every week. The amber cone is built from implied volatility, read from India VIX. The cyan cone is built from realized volatility, measured on weekly bars of the chart symbol. Both are scaled to the same horizon with the same geometry, so a difference in width is a difference in volatility and nothing else.
Shading is nested rather than overlapping. The neutral core is the range both measures agree on. The band outside it is the gap between them, coloured by whichever cone sits on the outside. That gap is the variance risk premium made visible, and when it changes colour, realized has overtaken implied.
The breach layer. Every bar that closes outside a cone is shaded. On its own this means very little, and that is the point most published expected-move scripts miss. A one-sigma cone is breached about 31.7 percent of the time by construction. So the readout states the expected rate next to the rate actually observed on your loaded history, for both cones separately.
If the implied cone is breached far less often than expected, implied volatility was systematically wider than the index needed. If it is breached more often, it was too narrow. That comparison is evidence. The shading alone is not.
The forward cone. From the current bar, projecting one horizon ahead, using the latest confirmed weekly volatility. Same nested construction. It is a distribution, not a direction.
How it is calculated
Implied leg. India VIX is an annualised implied volatility in percentage points, rescaled to the horizon by the square root of the horizon over 52.
Realized leg. Weekly log returns over the lookback, scaled to the horizon by the square root of the number of weeks. Three estimators:
Yang-Zhang, the default. Weekend-gap variance, open-to-close variance and the Rogers-Satchell range term, weighted by the standard k factor. It uses the whole weekly bar and is the most efficient and most drift-independent.
Std Dev. Sample standard deviation of weekly close-to-close log returns. Blind to everything inside the week.
ATR%. Weekly Average True Range as a fraction of price, times a factor you set. Range-aware, but the factor is a convention.
Bands are lognormal by default. That is not cosmetic: under a zero-drift random walk the expected breach rate of a lognormal band is exactly 2(1 - Phi(k)), so the observed-versus-expected comparison is exact rather than approximate.
Timeframes
All volatility maths runs in the weekly context, so the readings are identical on a 15-minute chart and on a weekly chart. Use any timeframe up to Weekly. Above Weekly the indicator disables itself and says why, because a weekly request from a monthly chart returns partial bars.
Alerts
Six: the implied-to-realized ratio crossing either threshold, and price closing outside either cone in either direction.
Limitations, stated plainly
India VIX measures implied volatility on NIFTY 50. The implied source is an input so you can pair another index with its own volatility index, not so you can run this on any symbol. Pairing one instrument's implied volatility with another's realized volatility is meaningless.
The breach sample counts weeks, not independent trials. Consecutive windows overlap by all but one week, so divide n by the horizon for a rough independent count and do not read small differences as significant.
The realized cone is estimated from the same series it is tested against, so its observed breach rate is not an out-of-sample result. The implied cone does not have this problem, which is part of why the two are reported apart.
Counting starts at the left edge of your loaded history, which varies by subscription and timeframe. Two users can see different n on the same symbol.
Square-root-of-time scaling assumes weekly returns are independent. Real index returns cluster in volatility, so it understates the tails in a stress regime and overstates them coming out of one.
The implied leg uses a single at-the-money volatility number and ignores skew, so it understates downside and overstates upside against the real option surface.
One sigma is a description of a distribution, not a boundary. Cones being broken is expected behaviour.
This plots volatility. It produces no directional signal, no entries and no exits.
Not financial advice. For education and research only.
Sürüm Notları
Description changedAçık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.