OPEN-SOURCE SCRIPT
Aggiornato Range Zones ATR

Range Zones ATR
Range Zones ATR is an open-source indicator designed to detect, validate, score, and maintain sideways price zones using ATR-normalized structure analysis.
The script is built for one specific purpose: identifying areas where price is behaving like a genuine horizontal range rather than a brief pause inside an ongoing trend. Instead of marking every local consolidation, it evaluates whether price is compressed relative to current volatility, whether directional pressure remains limited, whether the market is interacting with both sides of the structure, and whether internal movement stays balanced enough to justify treating the area as a meaningful zone of acceptance.
In practical terms, this indicator highlights parts of the chart where price is rotating within a contained area instead of moving cleanly in one direction. That makes it useful for studying balance, consolidation, containment, and possible expansion after compression.
What this indicator is
This indicator is a volatility-adjusted range structure detector.
Its main task is to answer a structural question:
Is price actually trading inside a valid sideways regime, or is the apparent consolidation too directional, too unstable, or too impulsive to be treated as a real range?
To answer that, the script does not rely on a single condition. It combines multiple filters and measurements into one process. A visible zone is only created after the candidate structure survives tests related to compression, trend pressure, slope behavior, duration, touch activity, oscillation, drift, and local expansion.
What this indicator shows
The script draws zones directly on the chart as horizontal boxes representing areas where price is being accepted inside a relatively contained environment.
The indicator can classify zones in three different ways:
Base Range
A confirmed sideways zone that passed the core validation logic.
Prime Range
A higher-quality confirmed zone with a stronger final score. These zones generally show cleaner balance, stronger containment, and better internal structure than a standard range.
HTF Confluence
A confirmed local zone that also overlaps with a valid higher-timeframe range context when the optional multi-timeframe feature is enabled.
These labels are structural descriptions, not trade commands. They are intended to help the user understand the character and quality of the detected range.
What the script measures
The indicator is built around the idea that a valid range should appear compressed, balanced, and relatively non-directional. To evaluate that, it measures several parts of market behavior.
Range width relative to ATR
The script compares the width of recent price envelopes to ATR. This allows the indicator to interpret range width relative to current volatility instead of using a fixed distance. A narrow range on one symbol may be wide on another, and a usable range on one timeframe may be insignificant on another. ATR normalization helps the script stay adaptive across different chart conditions.
Multiple internal envelopes
The script builds short-, medium-, and long-lookback envelopes from recent highs and lows. It then compares those candidates and selects the one that provides the best structural fit. This makes the detection process more flexible than relying on only one fixed lookback.
ADX trend pressure
A stable range normally should not exist in a strongly directional environment. The script uses ADX as part of its filter and scoring process to reduce the chance of classifying strong directional movement as sideways structure.
EMA slope and linear regression slope
A market can appear flat while still drifting directionally. To reduce that problem, the script checks both EMA slope and linear regression slope. This helps filter out sloped price action that does not behave like a clean horizontal range.
Minimum persistence
A valid range should remain stable for a meaningful number of bars before it is trusted. The script therefore includes minimum-bar confirmation logic so that very brief pauses do not become fully confirmed zones too early.
Touch behavior
A healthy range usually shows repeated interaction with its boundaries. The script tracks touches near the upper and lower edges of the candidate zone to confirm that price is actually rotating through the structure rather than clustering on one side.
Internal oscillation
A sideways regime should contain some back-and-forth movement. The script evaluates oscillatory behavior within the candidate zone to avoid treating a slow directional drift as balanced consolidation.
Drift and efficiency
The script checks how directly price is moving from one point to another. If movement becomes too efficient or too directional, that is less consistent with a true range. If movement is choppier and more rotational, the structure is more likely to qualify.
Impulsive movement
Strong impulsive candles can weaken or invalidate the idea of a stable range. The script uses expansion and impulse-related checks to reject candidates that are behaving too aggressively.
Higher-timeframe overlap
When the optional MTF context feature is enabled, the script checks whether the local zone overlaps a confirmed higher-timeframe range area. If the overlap is meaningful, the zone can receive a score boost and be classified with higher structural context.
How the detection process works
At a high level, the script follows this workflow:
First, it builds recent envelopes from highs and lows using several internal lookbacks.
Second, it measures whether those envelopes are sufficiently compressed relative to ATR.
Third, it combines that compression with trend and slope conditions such as ADX, EMA slope, and linear regression slope.
Fourth, if the environment looks suitable, it starts tracking a candidate zone instead of drawing a confirmed zone immediately.
Fifth, while the candidate is active, it evaluates persistence, touch count, oscillation, drift, path efficiency, and impulsive behavior.
Sixth, if the candidate survives enough structural tests, it becomes a visible zone on the chart.
Seventh, once a zone is active, it can continue, refine, merge with a nearby compatible zone, or terminate if price no longer behaves like the same sideways regime.
Finally, if breakout alerts are enabled, the script only considers a breakout confirmed after price closes beyond the zone edge plus an ATR-based buffer.
This process is important because the indicator is not designed to draw every small pause. It is designed to identify consolidations that behave like actual balance.
How to read the zones
A visible zone should be interpreted as an area where the script sees containment, acceptance, and relatively balanced price behavior.
That can help the user evaluate:
whether the market is still consolidating rather than trending,
whether price is continuing to rotate inside the same area,
whether one side of the structure is weakening,
whether the range remains healthy,
or whether the market may be transitioning from compression into expansion.
A Base Range means the structure passed the standard confirmation requirements.
A Prime Range means the same structure passed with a stronger overall score.
An HTF Confluence zone means the local structure also aligns with a broader higher-timeframe range area.
These classifications describe current market structure. They do not guarantee that price will remain inside the zone or that the next movement will occur in a particular direction.
How to use this indicator
This indicator is best used as a market-structure and chart-context tool.
One practical use is to study where price is being accepted inside a contained area. When price remains inside a confirmed zone and continues to interact with both edges, the market may still be operating in a balanced regime.
Another use is to monitor edge behavior. The upper and lower zone boundaries can serve as structural reference areas. Repeated rejection near one side, repeated return toward the middle, or clean acceptance outside the zone may help the user judge whether the range is still functioning or beginning to fail.
The breakout logic can also be used for structure monitoring. Because the script requires price to move beyond the zone edge with an ATR-based buffer, it is more selective than a simple boundary touch. This helps reduce reactions to small wick-only violations and shallow overshoots.
The optional higher-timeframe context can be used to compare local balance with broader structure. A local range that overlaps a confirmed higher-timeframe range may be more relevant than an isolated local pause.
The script can also be used to filter low-quality consolidation. Many apparent ranges are only temporary slowdowns inside a directional move. This indicator tries to reject many of those cases by requiring better balance, persistence, touch behavior, and non-directional structure before a zone is confirmed.
What makes this indicator different
This script differs from simpler range tools in several ways.
ATR-normalized detection
The indicator evaluates range width relative to ATR instead of using fixed-width boxes. This helps the same logic adapt to different volatility conditions, symbols, and timeframes.
Multi-factor validation
The script does not rely on a single trigger. It combines compression, trend pressure, slope analysis, persistence, touch activity, oscillation, drift, and efficiency into one structural decision process.
Candidate-to-confirmation workflow
Many range tools mark a zone as soon as price becomes temporarily narrow. This script first tracks a candidate, then confirms it only if the structure continues to behave like a true sideways regime.
Quality classification
The script separates normal confirmed ranges from stronger confirmed ranges. This helps distinguish ordinary structure from zones that achieve better internal scores.
Zone merge logic
Nearby zones that belong to the same horizontal regime can be merged. This is useful because real consolidations are often fragmented by minor interruptions or short empty gaps that still belong to the same broader balance area.
Higher-timeframe confluence
The optional MTF feature is used as structural context rather than as a separate signal engine. This allows local zones to be strengthened when they align with a broader confirmed range.
Active zone maintenance
Once confirmed, a zone is not simply frozen in place. The script can continue refining and extending the zone while price remains compatible with the same range logic.
Input overview
Mode
Conservative, Balanced, and Aggressive modes control how selective the detection process is. Conservative mode generally favors fewer and stricter zones. Aggressive mode allows broader coverage.
Preset
Scalping, Intraday, and Swing presets adjust internal lookbacks and structural behavior for different trading horizons.
Price Series
The script can use close, hl2, hlc3, or ohlc4 as its selected price source in parts of the scoring and filtering process, while envelopes remain based on highs and lows.
Sensitivity
Sensitivity changes how tightly or loosely candidate structures are interpreted.
Min Bars and Min Score
These settings define how much persistence and quality a candidate needs before it can qualify as a visible zone.
Trend Filter
This filter reduces the chance of labeling strong directional movement as sideways structure.
Merge controls
Merge Zones, Merge Threshold, Merge Gap Bars, and Bridge Merge control whether nearby compatible zones should be combined into one broader regime.
MTF controls
MTF Context, Higher TF, and MTF Boost allow local structure to be compared against confirmed higher-timeframe range structure.
Visual controls
The script includes settings for fill, borders, labels, theme handling, and score visibility.
Alerts
Optional alerts are available for newly confirmed zones and for breakout events beyond an active zone.
Best use cases
This indicator is designed for users who want to study consolidation structure rather than only directional trend behavior.
It can be useful for identifying balanced price areas, monitoring acceptance inside a horizontal regime, watching for continuation or breakdown of an existing range, studying compression before expansion, and comparing local structure with higher-timeframe context.
Important limitations
This script is an indicator, not a strategy. It does not execute trades and it does not provide backtest results.
Like any range-based method, it can become less effective in environments dominated by persistent directional expansion, abrupt trend transitions, or sudden volatility shocks. A detected zone is the script’s structural interpretation of current price behavior, not a guarantee that price will remain contained.
Open-source note
This script is published as open-source so users can inspect the logic, understand how the methodology works, and build on the idea in accordance with TradingView’s publication and reuse rules.
Range Zones ATR is an open-source indicator designed to detect, validate, score, and maintain sideways price zones using ATR-normalized structure analysis.
The script is built for one specific purpose: identifying areas where price is behaving like a genuine horizontal range rather than a brief pause inside an ongoing trend. Instead of marking every local consolidation, it evaluates whether price is compressed relative to current volatility, whether directional pressure remains limited, whether the market is interacting with both sides of the structure, and whether internal movement stays balanced enough to justify treating the area as a meaningful zone of acceptance.
In practical terms, this indicator highlights parts of the chart where price is rotating within a contained area instead of moving cleanly in one direction. That makes it useful for studying balance, consolidation, containment, and possible expansion after compression.
What this indicator is
This indicator is a volatility-adjusted range structure detector.
Its main task is to answer a structural question:
Is price actually trading inside a valid sideways regime, or is the apparent consolidation too directional, too unstable, or too impulsive to be treated as a real range?
To answer that, the script does not rely on a single condition. It combines multiple filters and measurements into one process. A visible zone is only created after the candidate structure survives tests related to compression, trend pressure, slope behavior, duration, touch activity, oscillation, drift, and local expansion.
What this indicator shows
The script draws zones directly on the chart as horizontal boxes representing areas where price is being accepted inside a relatively contained environment.
The indicator can classify zones in three different ways:
Base Range
A confirmed sideways zone that passed the core validation logic.
Prime Range
A higher-quality confirmed zone with a stronger final score. These zones generally show cleaner balance, stronger containment, and better internal structure than a standard range.
HTF Confluence
A confirmed local zone that also overlaps with a valid higher-timeframe range context when the optional multi-timeframe feature is enabled.
These labels are structural descriptions, not trade commands. They are intended to help the user understand the character and quality of the detected range.
What the script measures
The indicator is built around the idea that a valid range should appear compressed, balanced, and relatively non-directional. To evaluate that, it measures several parts of market behavior.
Range width relative to ATR
The script compares the width of recent price envelopes to ATR. This allows the indicator to interpret range width relative to current volatility instead of using a fixed distance. A narrow range on one symbol may be wide on another, and a usable range on one timeframe may be insignificant on another. ATR normalization helps the script stay adaptive across different chart conditions.
Multiple internal envelopes
The script builds short-, medium-, and long-lookback envelopes from recent highs and lows. It then compares those candidates and selects the one that provides the best structural fit. This makes the detection process more flexible than relying on only one fixed lookback.
ADX trend pressure
A stable range normally should not exist in a strongly directional environment. The script uses ADX as part of its filter and scoring process to reduce the chance of classifying strong directional movement as sideways structure.
EMA slope and linear regression slope
A market can appear flat while still drifting directionally. To reduce that problem, the script checks both EMA slope and linear regression slope. This helps filter out sloped price action that does not behave like a clean horizontal range.
Minimum persistence
A valid range should remain stable for a meaningful number of bars before it is trusted. The script therefore includes minimum-bar confirmation logic so that very brief pauses do not become fully confirmed zones too early.
Touch behavior
A healthy range usually shows repeated interaction with its boundaries. The script tracks touches near the upper and lower edges of the candidate zone to confirm that price is actually rotating through the structure rather than clustering on one side.
Internal oscillation
A sideways regime should contain some back-and-forth movement. The script evaluates oscillatory behavior within the candidate zone to avoid treating a slow directional drift as balanced consolidation.
Drift and efficiency
The script checks how directly price is moving from one point to another. If movement becomes too efficient or too directional, that is less consistent with a true range. If movement is choppier and more rotational, the structure is more likely to qualify.
Impulsive movement
Strong impulsive candles can weaken or invalidate the idea of a stable range. The script uses expansion and impulse-related checks to reject candidates that are behaving too aggressively.
Higher-timeframe overlap
When the optional MTF context feature is enabled, the script checks whether the local zone overlaps a confirmed higher-timeframe range area. If the overlap is meaningful, the zone can receive a score boost and be classified with higher structural context.
How the detection process works
At a high level, the script follows this workflow:
First, it builds recent envelopes from highs and lows using several internal lookbacks.
Second, it measures whether those envelopes are sufficiently compressed relative to ATR.
Third, it combines that compression with trend and slope conditions such as ADX, EMA slope, and linear regression slope.
Fourth, if the environment looks suitable, it starts tracking a candidate zone instead of drawing a confirmed zone immediately.
Fifth, while the candidate is active, it evaluates persistence, touch count, oscillation, drift, path efficiency, and impulsive behavior.
Sixth, if the candidate survives enough structural tests, it becomes a visible zone on the chart.
Seventh, once a zone is active, it can continue, refine, merge with a nearby compatible zone, or terminate if price no longer behaves like the same sideways regime.
Finally, if breakout alerts are enabled, the script only considers a breakout confirmed after price closes beyond the zone edge plus an ATR-based buffer.
This process is important because the indicator is not designed to draw every small pause. It is designed to identify consolidations that behave like actual balance.
How to read the zones
A visible zone should be interpreted as an area where the script sees containment, acceptance, and relatively balanced price behavior.
That can help the user evaluate:
whether the market is still consolidating rather than trending,
whether price is continuing to rotate inside the same area,
whether one side of the structure is weakening,
whether the range remains healthy,
or whether the market may be transitioning from compression into expansion.
A Base Range means the structure passed the standard confirmation requirements.
A Prime Range means the same structure passed with a stronger overall score.
An HTF Confluence zone means the local structure also aligns with a broader higher-timeframe range area.
These classifications describe current market structure. They do not guarantee that price will remain inside the zone or that the next movement will occur in a particular direction.
How to use this indicator
This indicator is best used as a market-structure and chart-context tool.
One practical use is to study where price is being accepted inside a contained area. When price remains inside a confirmed zone and continues to interact with both edges, the market may still be operating in a balanced regime.
Another use is to monitor edge behavior. The upper and lower zone boundaries can serve as structural reference areas. Repeated rejection near one side, repeated return toward the middle, or clean acceptance outside the zone may help the user judge whether the range is still functioning or beginning to fail.
The breakout logic can also be used for structure monitoring. Because the script requires price to move beyond the zone edge with an ATR-based buffer, it is more selective than a simple boundary touch. This helps reduce reactions to small wick-only violations and shallow overshoots.
The optional higher-timeframe context can be used to compare local balance with broader structure. A local range that overlaps a confirmed higher-timeframe range may be more relevant than an isolated local pause.
The script can also be used to filter low-quality consolidation. Many apparent ranges are only temporary slowdowns inside a directional move. This indicator tries to reject many of those cases by requiring better balance, persistence, touch behavior, and non-directional structure before a zone is confirmed.
What makes this indicator different
This script differs from simpler range tools in several ways.
ATR-normalized detection
The indicator evaluates range width relative to ATR instead of using fixed-width boxes. This helps the same logic adapt to different volatility conditions, symbols, and timeframes.
Multi-factor validation
The script does not rely on a single trigger. It combines compression, trend pressure, slope analysis, persistence, touch activity, oscillation, drift, and efficiency into one structural decision process.
Candidate-to-confirmation workflow
Many range tools mark a zone as soon as price becomes temporarily narrow. This script first tracks a candidate, then confirms it only if the structure continues to behave like a true sideways regime.
Quality classification
The script separates normal confirmed ranges from stronger confirmed ranges. This helps distinguish ordinary structure from zones that achieve better internal scores.
Zone merge logic
Nearby zones that belong to the same horizontal regime can be merged. This is useful because real consolidations are often fragmented by minor interruptions or short empty gaps that still belong to the same broader balance area.
Higher-timeframe confluence
The optional MTF feature is used as structural context rather than as a separate signal engine. This allows local zones to be strengthened when they align with a broader confirmed range.
Active zone maintenance
Once confirmed, a zone is not simply frozen in place. The script can continue refining and extending the zone while price remains compatible with the same range logic.
Input overview
Mode
Conservative, Balanced, and Aggressive modes control how selective the detection process is. Conservative mode generally favors fewer and stricter zones. Aggressive mode allows broader coverage.
Preset
Scalping, Intraday, and Swing presets adjust internal lookbacks and structural behavior for different trading horizons.
Price Series
The script can use close, hl2, hlc3, or ohlc4 as its selected price source in parts of the scoring and filtering process, while envelopes remain based on highs and lows.
Sensitivity
Sensitivity changes how tightly or loosely candidate structures are interpreted.
Min Bars and Min Score
These settings define how much persistence and quality a candidate needs before it can qualify as a visible zone.
Trend Filter
This filter reduces the chance of labeling strong directional movement as sideways structure.
Merge controls
Merge Zones, Merge Threshold, Merge Gap Bars, and Bridge Merge control whether nearby compatible zones should be combined into one broader regime.
MTF controls
MTF Context, Higher TF, and MTF Boost allow local structure to be compared against confirmed higher-timeframe range structure.
Visual controls
The script includes settings for fill, borders, labels, theme handling, and score visibility.
Alerts
Optional alerts are available for newly confirmed zones and for breakout events beyond an active zone.
Best use cases
This indicator is designed for users who want to study consolidation structure rather than only directional trend behavior.
It can be useful for identifying balanced price areas, monitoring acceptance inside a horizontal regime, watching for continuation or breakdown of an existing range, studying compression before expansion, and comparing local structure with higher-timeframe context.
Important limitations
This script is an indicator, not a strategy. It does not execute trades and it does not provide backtest results.
Like any range-based method, it can become less effective in environments dominated by persistent directional expansion, abrupt trend transitions, or sudden volatility shocks. A detected zone is the script’s structural interpretation of current price behavior, not a guarantee that price will remain contained.
Open-source note
This script is published as open-source so users can inspect the logic, understand how the methodology works, and build on the idea in accordance with TradingView’s publication and reuse rules.
Note di rilascio
What changed:A new "Colors" settings group has been added to the indicator inputs, giving users full control over zone and breakout colors directly from the settings panel. Previously, all colors were hardcoded and could not be modified without editing the source code.
New inputs in the "Colors" group:
Bullish Breakout — color applied to the border when a bullish breakout is confirmed
Bearish Breakout — color applied to the border when a bearish breakout is confirmed
Base Range Zone — fill and border color for standard detected zones
Prime Range Zone — fill and border color for high-quality zones
HTF Confluence Zone — fill and border color for multi-timeframe confluence zones
Expired Zone Border — border color applied to zones after they close or expire
Why it was changed:
Different chart themes, asset types, and personal preferences require different color schemes. Hardcoded colors created visual conflicts on light-themed charts and made it impossible for users to match the indicator to their existing setup. This change removes that limitation entirely.
Existing inputs unaffected:
Label Text Color and Label Size were already configurable under the "Visuals" group and remain there unchanged. No logic, calculation, detection, or alert behavior has been modified in this update.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
💎Get instant access here:
malibuta.com/
malibuta.com/
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
💎Get instant access here:
malibuta.com/
malibuta.com/
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.