OPEN-SOURCE SCRIPT
Volatility Regime Radar (tanh normalized)

Overview
This indicator measures directional volatility by separating bullish price movement volatility from bearish price movement volatility, normalizing their difference using a hyperbolic tangent (tanh) function, and plotting the result as a regime detection oscillator. It helps traders identify whether upside or downside volatility is currently dominant — and by how much — without relying on price direction alone.
Core Concept
Standard ATR treats all price movement equally, regardless of direction. This indicator splits the True Range into two components:
Upside TR — True Range recorded only on bars where the market closed flat or higher than the previous close
Downside TR — True Range recorded only on bars where the market closed lower than the previous close
Each component is smoothed independently, compared against its own exponential moving average as a baseline, normalized using rolling standard deviation, and then compressed into the −1 to +1 range via the tanh function. The difference between the two normalized values becomes the primary signal.
Step-by-Step Calculation
1. True Range Split
Each bar's True Range is routed into either the upside bucket or the downside bucket depending on whether the bar closed higher or lower. The unused bucket receives zero for that bar.
2. Directional Smoothing
Each bucket is smoothed using the chosen method — RMA, SMA, EMA, or WMA — over the ATR Length period. This produces a smoothed upside ATR and a smoothed downside ATR.
3. Baseline via EMA
Each smoothed ATR is then passed through a second EMA over the ATR EMA Length period. This second EMA acts as a dynamic reference level, representing the "normal" state of each directional volatility series.
4. Distance from Baseline
The difference between the current smoothed ATR and its EMA baseline is computed for each direction. A positive distance means directional volatility is currently above its recent norm (expanding); a negative distance means it is contracting below norm.
5. Standard Deviation Normalization
Each distance value is divided by its own rolling standard deviation, calculated over the Normalization Length period. This step makes the readings comparable across different instruments, timeframes, and market conditions without any manual adjustment.
6. tanh Compression
The normalized distance is passed through the hyperbolic tangent function, which compresses any input into a value strictly between −1 and +1. Large positive readings saturate near +1; large negative readings saturate near −1. Moderate moves produce proportional values in between. This makes the oscillator inherently bounded and stable.
7. Spread Calculation
The downside normalized value is visually inverted — flipped below zero — so that bullish and bearish volatility occupy their natural positions on opposite sides of the zero line. The spread is then the difference between the upside value and this inverted downside value. When the spread is positive, upside volatility dominates; when negative, downside volatility dominates. The typical range of the spread is approximately −2 to +2.
8. Smoothed Spread
The spread is passed through a final EMA over the Spread Smoothing Length period. This smoothed version is slower to react and serves as the regime signal — it drives the background color and the stats table readout.
Visual Elements
Upside volatility bars/line — Represents normalized upside volatility. Color fades from gray when near baseline to bright green as upside volatility expands well above its norm.
Downside volatility bars/line — Represents normalized downside volatility, displayed below zero. Color fades from gray to bright red as downside volatility expands.
Spread — The raw difference between upside and downside normalized values. Displayed in yellow by default. This reacts quickly to changes in volatility balance.
Smoothed Spread — A slower, EMA-filtered version of the spread. Displayed in aqua by default. This is the regime signal.
Zero line — The neutral reference. When both directions are equally active, all lines converge here.
Threshold lines — Horizontal reference lines placed at the positive and negative Regime Threshold values. The smoothed spread must cross these to trigger a regime declaration.
Background color — Green tint when the bull volatility regime is active, red tint when the bear volatility regime is active, gray when neutral.
Stats Table
The table in the top-right corner displays the current state of all key values at a glance.
Upside normalized value — The current tanh-compressed reading for upside volatility.
Downside normalized value (inverted) — The current tanh-compressed reading for downside volatility, shown as a negative number for visual consistency.
Spread — The current raw spread between upside and downside.
Smoothed Spread — The current EMA-filtered spread used for regime detection.
Threshold — The configured regime threshold value.
Dominance — Shows whether upside or downside volatility is currently larger. Displays "Up," "Down," or "Balanced."
Regime — The current regime declaration: "Bull Vol," "Bear Vol," or "Neutral," based on whether the smoothed spread has crossed the threshold in either direction.
The table can be hidden using the Show Stats Table toggle in the settings.
Settings
ATR Length (default: 14) — The lookback period for smoothing the raw directional True Range values.
ATR EMA Length (default: 14) — The EMA period applied to each smoothed directional ATR to produce the dynamic baseline.
Normalization Length (default: 50) — The rolling window used to calculate the standard deviation for normalization. Larger values produce a more stable, slower signal.
ATR Smoothing (default: RMA) — The smoothing method applied to the raw True Range. RMA is equivalent to Wilder's smoothing, the same method used in the classic ATR calculation. SMA, EMA, and WMA are also available.
View Mode (default: All) — Controls which series are visible. Options are: Up/Down only, Spread only, Smoothed Spread only, or All.
Histogram Mode (default: On) — When enabled, all series are rendered as histograms. When disabled, they are shown as lines.
Spread Smoothing Length (default: 9) — The EMA length applied to the raw spread to produce the smoothed regime signal.
Regime Threshold (default: 0.20) — The level the smoothed spread must exceed to declare an active bull or bear volatility regime.
Spread Color (default: Yellow) — The color used for the raw spread plot.
Smoothed Spread Color (default: Aqua) — The color used for the smoothed spread line.
Show Stats Table (default: On) — Toggles the stats table in the top-right corner on or off.
How to Read the Indicator
Smoothed spread rising above the positive threshold — Upside volatility is expanding meaningfully above downside volatility. The background turns green and the regime reads "Bull Vol." Conditions favor bullish momentum.
Smoothed spread falling below the negative threshold — Downside volatility is dominant. The background turns red and the regime reads "Bear Vol." Conditions favor bearish momentum.
Smoothed spread between the thresholds — Neither direction has a clear edge. The background stays gray and the regime reads "Neutral." Directional conviction is low.
Upside bars brightening while downside bars stay muted — Bullish volatility is activating. This often precedes or accompanies a trending upward move.
Downside bars deepening in red while upside fades — Bearish volatility is taking over, even if price has not yet moved sharply lower.
Trading Applications
Regime-based directional filter — Use the background color and regime label to define which direction you are willing to trade. Taking longs only during green regimes and shorts only during red regimes filters out a large portion of counter-trend noise.
Volatility expansion entries — When the smoothed spread crosses the threshold from the neutral zone, it marks the beginning of a regime. This crossover can be used as a trigger or confirmation signal for trend-following strategies.
Regime change alerts — When the smoothed spread flips from one extreme to the other and breaks through the opposite threshold, a full regime reversal is underway. These moments can signal significant shifts in market character.
Momentum divergence — If price makes new highs while the upside volatility reading is declining, or if downside volatility begins expanding while price is still rising, it suggests weakening momentum and potential reversal ahead.
Exhaustion and mean reversion — When the spread reaches extreme levels near ±2 and begins pulling back toward zero, directional volatility is likely exhausting. This can be a timing aid for fading overextended moves or taking partial profits.
Multi-timeframe regime alignment — Load the indicator on a higher timeframe to establish the dominant volatility regime, then use your execution timeframe to find entries that align with the higher-timeframe regime direction.
Important Notes
The tanh function ensures that all normalized values remain bounded between −1 and +1 regardless of the instrument or timeframe, so no manual recalibration is needed when switching markets. The spread's typical range of −2 to +2 follows naturally from combining two bounded values.
A smoothed spread near zero does not mean the market is quiet — it means that upside and downside volatility are roughly equal in magnitude. Both could be elevated simultaneously while the spread remains near zero.
RMA smoothing tends to weight recent data heavily and is the most common choice for ATR-based calculations. EMA reacts faster; SMA treats all bars equally; WMA emphasizes the most recent bars in a linear fashion. The choice of smoothing method affects the responsiveness of the directional ATR values.
Increasing the Normalization Length slows the indicator's response and makes regime transitions less frequent. Decreasing it speeds up the signal but may produce more noise.
Recommended Settings for Short Timeframes
On shorter timeframes — such as 1-minute, 3-minute, or 5-minute charts — price action is inherently noisier and individual bars carry less meaningful information on their own. To compensate for this, the ATR Length and ATR EMA Length are both set to 100 instead of the default 14. This significantly increases the smoothing window, allowing the indicator to filter out short-term volatility spikes and focus on more meaningful directional shifts. The result is a cleaner, more reliable signal that is less prone to whipsawing on fast charts.
Additionally, Histogram Mode is turned off on this chart. With the series displayed as lines rather than histograms, it is easier to track the flow and curvature of the spread and smoothed spread over time, making regime transitions and momentum shifts more visually clear.
Disclaimer
This indicator is provided for educational and informational purposes only. It does not constitute financial advice, investment recommendations, or a solicitation to buy or sell any financial instrument. Past performance of any strategy or signal derived from this tool is not indicative of future results. All trading involves risk, including the possible loss of capital invested. Always conduct your own due diligence and consult a qualified financial professional before making any trading or investment decisions. The author assumes no responsibility for any losses incurred as a result of using this indicator.
This indicator measures directional volatility by separating bullish price movement volatility from bearish price movement volatility, normalizing their difference using a hyperbolic tangent (tanh) function, and plotting the result as a regime detection oscillator. It helps traders identify whether upside or downside volatility is currently dominant — and by how much — without relying on price direction alone.
Core Concept
Standard ATR treats all price movement equally, regardless of direction. This indicator splits the True Range into two components:
Upside TR — True Range recorded only on bars where the market closed flat or higher than the previous close
Downside TR — True Range recorded only on bars where the market closed lower than the previous close
Each component is smoothed independently, compared against its own exponential moving average as a baseline, normalized using rolling standard deviation, and then compressed into the −1 to +1 range via the tanh function. The difference between the two normalized values becomes the primary signal.
Step-by-Step Calculation
1. True Range Split
Each bar's True Range is routed into either the upside bucket or the downside bucket depending on whether the bar closed higher or lower. The unused bucket receives zero for that bar.
2. Directional Smoothing
Each bucket is smoothed using the chosen method — RMA, SMA, EMA, or WMA — over the ATR Length period. This produces a smoothed upside ATR and a smoothed downside ATR.
3. Baseline via EMA
Each smoothed ATR is then passed through a second EMA over the ATR EMA Length period. This second EMA acts as a dynamic reference level, representing the "normal" state of each directional volatility series.
4. Distance from Baseline
The difference between the current smoothed ATR and its EMA baseline is computed for each direction. A positive distance means directional volatility is currently above its recent norm (expanding); a negative distance means it is contracting below norm.
5. Standard Deviation Normalization
Each distance value is divided by its own rolling standard deviation, calculated over the Normalization Length period. This step makes the readings comparable across different instruments, timeframes, and market conditions without any manual adjustment.
6. tanh Compression
The normalized distance is passed through the hyperbolic tangent function, which compresses any input into a value strictly between −1 and +1. Large positive readings saturate near +1; large negative readings saturate near −1. Moderate moves produce proportional values in between. This makes the oscillator inherently bounded and stable.
7. Spread Calculation
The downside normalized value is visually inverted — flipped below zero — so that bullish and bearish volatility occupy their natural positions on opposite sides of the zero line. The spread is then the difference between the upside value and this inverted downside value. When the spread is positive, upside volatility dominates; when negative, downside volatility dominates. The typical range of the spread is approximately −2 to +2.
8. Smoothed Spread
The spread is passed through a final EMA over the Spread Smoothing Length period. This smoothed version is slower to react and serves as the regime signal — it drives the background color and the stats table readout.
Visual Elements
Upside volatility bars/line — Represents normalized upside volatility. Color fades from gray when near baseline to bright green as upside volatility expands well above its norm.
Downside volatility bars/line — Represents normalized downside volatility, displayed below zero. Color fades from gray to bright red as downside volatility expands.
Spread — The raw difference between upside and downside normalized values. Displayed in yellow by default. This reacts quickly to changes in volatility balance.
Smoothed Spread — A slower, EMA-filtered version of the spread. Displayed in aqua by default. This is the regime signal.
Zero line — The neutral reference. When both directions are equally active, all lines converge here.
Threshold lines — Horizontal reference lines placed at the positive and negative Regime Threshold values. The smoothed spread must cross these to trigger a regime declaration.
Background color — Green tint when the bull volatility regime is active, red tint when the bear volatility regime is active, gray when neutral.
Stats Table
The table in the top-right corner displays the current state of all key values at a glance.
Upside normalized value — The current tanh-compressed reading for upside volatility.
Downside normalized value (inverted) — The current tanh-compressed reading for downside volatility, shown as a negative number for visual consistency.
Spread — The current raw spread between upside and downside.
Smoothed Spread — The current EMA-filtered spread used for regime detection.
Threshold — The configured regime threshold value.
Dominance — Shows whether upside or downside volatility is currently larger. Displays "Up," "Down," or "Balanced."
Regime — The current regime declaration: "Bull Vol," "Bear Vol," or "Neutral," based on whether the smoothed spread has crossed the threshold in either direction.
The table can be hidden using the Show Stats Table toggle in the settings.
Settings
ATR Length (default: 14) — The lookback period for smoothing the raw directional True Range values.
ATR EMA Length (default: 14) — The EMA period applied to each smoothed directional ATR to produce the dynamic baseline.
Normalization Length (default: 50) — The rolling window used to calculate the standard deviation for normalization. Larger values produce a more stable, slower signal.
ATR Smoothing (default: RMA) — The smoothing method applied to the raw True Range. RMA is equivalent to Wilder's smoothing, the same method used in the classic ATR calculation. SMA, EMA, and WMA are also available.
View Mode (default: All) — Controls which series are visible. Options are: Up/Down only, Spread only, Smoothed Spread only, or All.
Histogram Mode (default: On) — When enabled, all series are rendered as histograms. When disabled, they are shown as lines.
Spread Smoothing Length (default: 9) — The EMA length applied to the raw spread to produce the smoothed regime signal.
Regime Threshold (default: 0.20) — The level the smoothed spread must exceed to declare an active bull or bear volatility regime.
Spread Color (default: Yellow) — The color used for the raw spread plot.
Smoothed Spread Color (default: Aqua) — The color used for the smoothed spread line.
Show Stats Table (default: On) — Toggles the stats table in the top-right corner on or off.
How to Read the Indicator
Smoothed spread rising above the positive threshold — Upside volatility is expanding meaningfully above downside volatility. The background turns green and the regime reads "Bull Vol." Conditions favor bullish momentum.
Smoothed spread falling below the negative threshold — Downside volatility is dominant. The background turns red and the regime reads "Bear Vol." Conditions favor bearish momentum.
Smoothed spread between the thresholds — Neither direction has a clear edge. The background stays gray and the regime reads "Neutral." Directional conviction is low.
Upside bars brightening while downside bars stay muted — Bullish volatility is activating. This often precedes or accompanies a trending upward move.
Downside bars deepening in red while upside fades — Bearish volatility is taking over, even if price has not yet moved sharply lower.
Trading Applications
Regime-based directional filter — Use the background color and regime label to define which direction you are willing to trade. Taking longs only during green regimes and shorts only during red regimes filters out a large portion of counter-trend noise.
Volatility expansion entries — When the smoothed spread crosses the threshold from the neutral zone, it marks the beginning of a regime. This crossover can be used as a trigger or confirmation signal for trend-following strategies.
Regime change alerts — When the smoothed spread flips from one extreme to the other and breaks through the opposite threshold, a full regime reversal is underway. These moments can signal significant shifts in market character.
Momentum divergence — If price makes new highs while the upside volatility reading is declining, or if downside volatility begins expanding while price is still rising, it suggests weakening momentum and potential reversal ahead.
Exhaustion and mean reversion — When the spread reaches extreme levels near ±2 and begins pulling back toward zero, directional volatility is likely exhausting. This can be a timing aid for fading overextended moves or taking partial profits.
Multi-timeframe regime alignment — Load the indicator on a higher timeframe to establish the dominant volatility regime, then use your execution timeframe to find entries that align with the higher-timeframe regime direction.
Important Notes
The tanh function ensures that all normalized values remain bounded between −1 and +1 regardless of the instrument or timeframe, so no manual recalibration is needed when switching markets. The spread's typical range of −2 to +2 follows naturally from combining two bounded values.
A smoothed spread near zero does not mean the market is quiet — it means that upside and downside volatility are roughly equal in magnitude. Both could be elevated simultaneously while the spread remains near zero.
RMA smoothing tends to weight recent data heavily and is the most common choice for ATR-based calculations. EMA reacts faster; SMA treats all bars equally; WMA emphasizes the most recent bars in a linear fashion. The choice of smoothing method affects the responsiveness of the directional ATR values.
Increasing the Normalization Length slows the indicator's response and makes regime transitions less frequent. Decreasing it speeds up the signal but may produce more noise.
Recommended Settings for Short Timeframes
On shorter timeframes — such as 1-minute, 3-minute, or 5-minute charts — price action is inherently noisier and individual bars carry less meaningful information on their own. To compensate for this, the ATR Length and ATR EMA Length are both set to 100 instead of the default 14. This significantly increases the smoothing window, allowing the indicator to filter out short-term volatility spikes and focus on more meaningful directional shifts. The result is a cleaner, more reliable signal that is less prone to whipsawing on fast charts.
Additionally, Histogram Mode is turned off on this chart. With the series displayed as lines rather than histograms, it is easier to track the flow and curvature of the spread and smoothed spread over time, making regime transitions and momentum shifts more visually clear.
Disclaimer
This indicator is provided for educational and informational purposes only. It does not constitute financial advice, investment recommendations, or a solicitation to buy or sell any financial instrument. Past performance of any strategy or signal derived from this tool is not indicative of future results. All trading involves risk, including the possible loss of capital invested. Always conduct your own due diligence and consult a qualified financial professional before making any trading or investment decisions. The author assumes no responsibility for any losses incurred as a result of using this indicator.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
For help and support, feel free to contact:
wa.me/905469061306
wa.me/905469061306
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
For help and support, feel free to contact:
wa.me/905469061306
wa.me/905469061306
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.