Volatility Prism [JOAT]Volatility Prism
Introduction
Volatility Prism is an open-source dual Bollinger Band envelope system with percentile-based bandwidth squeeze detection and Stochastic RSI confirmation. It renders two independent envelopes — an inner band at a configurable standard deviation multiplier and an outer band at a wider multiplier — with gradient fills that color dynamically based on whether price is in a bullish or bearish position relative to the moving average basis. When the bandwidth compresses to a historically low percentile, a squeeze state is declared. When the squeeze releases, an expansion signal fires.
The problem Volatility Prism solves is that volatility states are cyclical: periods of compression (squeeze) reliably precede periods of expansion (breakout), and the direction of the breakout is where the opportunity lies. By combining a statistically-based squeeze detector — which uses percentile thresholds rather than fixed bandwidth levels — with Stochastic RSI extreme confirmation, Volatility Prism identifies both the compression state and the likely directional bias of the coming expansion simultaneously.
Core Concepts
1. Dual Bollinger Band Structure
Two separate Bollinger Band pairs share the same basis (SMA of the source) but use different standard deviation multipliers. The inner band (default 2.0x) is the primary envelope. The outer band (default 3.0x) defines the extreme extension zone. Price trading beyond the inner band but inside the outer band is in the elevated zone. Price trading beyond the outer band is in a statistical extreme:
basis = ta.sma(src, bbLen)
dev = ta.stdev(src, bbLen)
upper1 = basis + bbMult1 * dev // Inner upper
lower1 = basis - bbMult1 * dev // Inner lower
upper2 = basis + bbMult2 * dev // Outer upper
lower2 = basis - bbMult2 * dev // Outer lower
The trend bias is determined by whether the close is above or below the basis. When bullish, all envelope lines and fills render in the bullish color. When bearish, they render in the bearish color. This makes the trend state immediately visible from the envelope color alone.
2. Gradient Envelope Fills
Four gradient fills create the visual envelope structure. The inner fills gradient from a near-opaque shade at the band edge to a nearly transparent shade at the basis, creating a density effect that visually represents how far price is from the center. The outer fills extend this gradient into the extreme zone at reduced opacity, cleanly separating the normal, elevated, and extreme price zones:
fill(basisPlot, upper1Plot, upper1, basis, color.new(envCol, 85), color.new(envCol, 98), "Upper Inner Fill")
fill(upper1Plot, upper2Plot, upper2, upper1, color.new(envCol, 75), color.new(envCol, 88), "Upper Outer Fill")
3. Percentile-Based Bandwidth Squeeze Detection
The bandwidth (the width of the inner band as a percentage of the basis) is computed on each bar and added to a rolling history array of configurable length. The current bandwidth is compared to the percentile threshold of that history — if the current bandwidth is below the configured percentile (default 15th percentile), the squeeze state is active:
bandwidth = basis > 0 ? (upper1 - lower1) / basis * 100 : 0.0
// Sort history and find threshold at configured percentile
threshIdx = int(array.size(sorted) * sqzPctile / 100) - 1
sqzThreshold = array.get(sorted, threshIdx)
isSqueezing = bandwidth <= sqzThreshold
This approach adapts to the instrument and timeframe automatically — a 15th percentile squeeze on a low-volatility bond future and on a high-volatility crypto asset will both correctly identify when that specific instrument is in an unusually compressed state relative to its own history.
4. Stochastic RSI Extreme Confirmation
The Stochastic RSI (an oscillator that applies Stochastic logic to RSI values) provides momentum extreme confirmation. Overbought and oversold readings from the K and D lines confirm when band extremes coincide with momentum extremes, strengthening band rejection signals:
rsiVal = ta.rsi(src, rsiLen)
stochVal = ta.stoch(rsiVal, rsiVal, rsiVal, stochLen)
kLine = ta.sma(stochVal, smoothK)
dLine = ta.sma(kLine, smoothD)
stochOB = kLine > upperLim and dLine > upperLim // Overbought
stochOS = kLine < lowerLim and dLine < lowerLim // Oversold
5. Band Rejection Signals and Squeeze Breakout
Three signal types are generated. Bullish band rejection fires when price was below the inner lower band on the previous bar and closes back above it, with Stochastic RSI confirming oversold — a failed breakdown with momentum confirmation. Bearish band rejection fires on the symmetric condition above the inner upper band. Squeeze Breakout fires on the first bar that transitions from squeeze to non-squeeze state — the moment the bandwidth begins expanding:
bearRejection = close > upper1 and close <= upper1 and stochOB
bullRejection = close < lower1 and close >= lower1 and stochOS
sqzBreakout = isSqueezing and not isSqueezing
6. Band Price Labels at the Right Edge
All five band lines (U2, U1, MA, L1, L2) receive price labels at the right edge of the chart. These labels update every bar to show the current price of each level, eliminating the need to hover over lines or read the y-axis to determine band values:
if barstate.islast and showBandLbls
lblU2 := label.new(bar_index + 2, upper2,
"U2 " + str.tostring(upper2, format.mintick),
style=label.style_label_right, ...)
Features
Dual Bollinger Band envelopes: Inner and outer bands with independently configurable multipliers
Adaptive gradient fills: Four gradient fills (inner upper, inner lower, outer upper, outer lower) color dynamically with trend bias
Dynamic trend coloring: All envelope elements switch between bullish and bearish colors based on close vs. basis
Percentile-based squeeze detection: Bandwidth compared to a configurable percentile of its rolling history — adapts to any instrument's volatility profile
Configurable squeeze lookback: Rolling bandwidth history window from 20 to 500 bars
Squeeze background shading: Optional chart background shading during active squeeze state
Stochastic RSI confirmation: K and D line extreme zones confirm band rejection signal quality
Three signal types: Bull Rejection, Bear Rejection, and Squeeze Breakout markers with distinct shapes
Band price labels at right edge: Live price labels for all five band levels (U2, U1, MA, L1, L2) at bar_index + 2
Institutional dashboard (top right): 11-row table with Volatility state (SQUEEZE/EXPANDING), Bandwidth %, Trend, StochRSI state, K and D values, Basis price, and Envelope range
Fully configurable inputs: BB length, both multipliers, squeeze lookback and percentile, Stochastic RSI parameters, and all colors independently adjustable
Alerts: Bull Rejection, Bear Rejection, Squeeze Breakout, and Squeeze Entry alertconditions
Input Parameters
Bollinger Bands:
Source: Price source (default: close)
BB Length: MA and standard deviation period (default: 20)
Inner Mult: Standard deviation multiplier for inner bands (default: 2.0)
Outer Mult: Standard deviation multiplier for outer bands (default: 3.0)
Squeeze Detection:
Bandwidth Lookback: Rolling history window for percentile calculation (default: 120 bars)
Squeeze Percentile: Bandwidth percentile below which squeeze is active (default: 15th)
Stochastic RSI:
K Smoothing (default: 3), D Smoothing (default: 3)
RSI Length (default: 14), Stochastic Length (default: 14)
Overbought level (default: 80), Oversold level (default: 20)
Display:
Show Dashboard toggle
Squeeze Background toggle
Band Price Labels toggle
Bullish Envelope color, Bearish Envelope color, Basis Line color, Squeeze Background color
How to Use This Indicator
Step 1: Identify the Volatility State
The dashboard's Volatility row shows SQUEEZE (yellow) or EXPANDING (gray). When SQUEEZE is active, the chart background shades yellow. A squeeze state means bandwidth has compressed to a historically low percentile — the market is loading energy for a directional move.
Step 2: Watch for Squeeze Breakout Signals
The cross (x) marker appears at the first bar that exits a squeeze. This is the moment bandwidth begins expanding. The direction of the breakout bar (bullish or bearish candle) combined with the trend color of the envelope provides the directional lean for the expansion phase.
Step 3: Interpret Envelope Color for Trend Bias
When all envelope elements are teal, price is above the basis — bullish bias. When all elements are orange, price is below the basis — bearish bias. Use the envelope color as a continuous trend indicator overlaid directly on the price.
Step 4: React to Band Rejection Diamonds
Diamond markers at the band edge indicate price failed to sustain a move beyond the inner band and recovered inside, with Stochastic RSI confirming the extreme. These are mean-reversion entry signals — price rejected the statistical extreme with momentum confirmation.
Step 5: Reference Band Price Labels
The right-edge labels show the current price of each band level. Use these when planning take-profit targets (opposite band) or stop-loss placement (outer band beyond entry) without needing to manually read prices from band lines.
Indicator Limitations
The squeeze detector requires a minimum of sqzLen bars of bandwidth history to activate. On short charts or immediately after the indicator is applied, the squeeze state will not register until enough history is accumulated
The percentile-based squeeze threshold adapts to the lookback window. A longer lookback produces a more stable threshold; a shorter lookback adapts faster but may produce more frequent squeeze entries and exits
Band rejection signals require the close to recover inside the band on the bar immediately following the outside close. Multi-bar breakouts that recover more slowly are not detected as rejections
Squeeze Breakout markers fire on the first bar exiting a squeeze regardless of candle size or direction. They do not independently confirm the breakout direction — the envelope trend color and Stochastic RSI must be used to assess directional bias
Stochastic RSI is a double-transformed oscillator (RSI → Stochastic). It can reach and hold extreme levels for extended periods in strong trends, producing frequent overbought or oversold readings that reduce the specificity of band rejection confirmation
Originality Statement
Volatility Prism is original in its adaptive, percentile-based squeeze detection combined with a dual-envelope gradient structure and Stochastic RSI extreme confirmation with right-edge band price labels. This indicator is published because:
Using the rolling percentile of bandwidth history — rather than fixed bandwidth values or the classic Keltner Channel comparison method — for squeeze detection provides an instrument-adaptive and timeframe-adaptive threshold that requires no manual calibration
The dual-envelope structure (inner and outer bands) with four independent gradient fills that change color based on real-time trend bias creates a visually rich, information-dense chart overlay without adding separate indicator panes
The right-edge band price labels for all five band levels eliminate a common usability friction point in Bollinger Band analysis, where traders must hover over lines or estimate prices from the y-axis scale
The three-signal system (Bull Rejection, Bear Rejection, Squeeze Breakout) operating from two independent mechanisms (band geometry + Stochastic RSI for rejections, bandwidth percentile for breakout) provides distinct signal categories suited to different trading styles
Disclaimer
This indicator is provided for educational and informational purposes only. It is not financial advice or a recommendation to buy or sell any financial instrument. Trading involves substantial risk of loss. Bollinger Bands and Stochastic RSI readings are historical statistical tools. Squeeze states can persist for extended periods without producing a breakout, and breakouts can occur in either direction. Band rejection signals do not guarantee price will reverse from the band. Always use proper risk management. The author is not responsible for any trading losses resulting from the use of this indicator.
-Made with passion by jackofalltrades
مؤشر Pine Script®






















