OPEN-SOURCE SCRIPT
Adaptive Reaction Zones

Adaptive Reaction Zones is an adaptive price-reaction level indicator designed to automatically identify areas where the market has repeatedly reversed, slowed down, or changed direction.
Rather than plotting every local high and low, the indicator:
detects confirmed price reactions;
evaluates the quality of each reaction;
groups nearby reactions into price clusters;
ranks the resulting areas;
displays only the most relevant support and resistance levels.
The chart shows the calculated center of each identified reaction area:
🔴 Red lines represent levels above the current price.
🟢 Green lines represent levels below the current price.
Each label displays the exact level price and its percentage distance from the current market price.
🎯 Purpose of the Indicator
Adaptive Reaction Zones provides a structured map of nearby price areas that have previously generated meaningful market reactions.
The indicator can be used to:
identify nearby support and resistance areas;
measure the distance to potentially significant price levels;
plan possible profit-taking areas;
locate zones where future price behavior may require closer observation;
analyze level breakouts and potential role reversals;
create alerts for crossings of relevant price areas.
The indicator is not a standalone trading strategy and does not generate mandatory buy or sell signals.
Its purpose is to provide an objective map of historical price reactions that traders can combine with trend analysis, market structure, volume, volatility, and other forms of analysis.
⚙️ How the Algorithm Works
1. Detecting Confirmed Price Reactions
The calculation begins with confirmed local highs and lows.
Users can select one of two reaction sources:
High / Low
The algorithm analyzes the full high and low values of each candle, including its wicks.
Candle body
The algorithm uses the boundaries of the candle body and excludes the extreme wick values.
The Pivot confirmation setting determines how many bars are required on each side of a local high or low before the reaction is confirmed.
As a result, a reaction is not included in the calculations at the exact moment the extreme occurs. It is added only after subsequent bars confirm that the point was a local high or low.
A lower setting:
increases the sensitivity of the algorithm;
produces more confirmed reactions;
allows the indicator to respond to smaller local movements.
A higher setting:
selects more pronounced market extremes;
reduces the number of secondary reactions;
increases the confirmation delay.
2. Evaluating Reaction Quality
The algorithm does not treat every confirmed local high or low as equally important.
Each reaction receives an individual quality score based on two components.
Reaction Candle Structure
For a reaction from a local high, the algorithm evaluates the upper wick relative to the candle’s total range.
For a reaction from a local low, it evaluates the lower wick.
A pronounced wick may indicate that price was rejected from that area by market participants.
Subsequent Price Movement
The algorithm also measures how far price moved away from the detected extreme during the period required to confirm the reaction.
This movement is normalized using ATR, allowing reactions formed under different volatility conditions to be compared on a consistent basis.
In the final calculation, the subsequent price movement receives slightly more weight than the candle structure.
This means that an isolated or insignificant extreme receives a lower score than a reaction followed by a meaningful price move in the opposite direction.
3. Adaptive Reaction Clustering
The market rarely reacts several times at exactly the same price.
More commonly, reactions occur within the same broader price area but at slightly different values. For this reason, Adaptive Reaction Zones groups nearby reactions into adaptive price clusters.
The cluster width is not fixed. It is calculated using:
the current ATR value;
the market range over the selected lookback period;
the instrument’s minimum tick size.
The algorithm compares the width calculated from ATR with a percentage of the broader market range and uses the larger value.
This allows the clustering distance to adapt automatically to:
current volatility;
the scale of movement in the selected instrument;
the characteristics of the market and timeframe.
ATR is not used as a separate trading signal in this indicator. It is used to normalize volatility, determine the adaptive cluster width, and calculate the minimum spacing between displayed levels.
4. Calculating the Center of a Price Area
When a new reaction is confirmed, the algorithm searches for the nearest suitable cluster.
If the distance to an existing cluster is within the calculated tolerance, the reaction is added to that cluster.
If no suitable cluster exists, a new price area is created.
The center of each cluster is calculated as a weighted average of all reactions included in it.
More recent reactions receive greater weight. The influence of older reactions gradually decreases according to the Historical reaction weight setting.
For each cluster, the algorithm stores:
the number of reactions;
the combined reaction-quality value;
the upper and lower boundaries of the area;
the bar of the most recent reaction;
the number of reactions from local highs;
the number of reactions from local lows.
🧠 How Level Significance Is Evaluated
After the clusters have been created, each cluster receives a composite score.
The score is based on five main characteristics.
Number of Reactions
The more confirmed reactions that have occurred within the same price area, the higher its base significance.
Reaction Quality
Clusters containing pronounced candle rejections and stronger subsequent price movements receive a higher score.
Recency
Recent reactions receive more weight than areas that have not interacted with price for a long time.
Cluster Tightness
Reactions concentrated within a relatively narrow price range receive a higher score than reactions spread across a wider area.
Role Reversal
A cluster receives additional weight when the same price area has generated reactions from both local highs and local lows.
This allows the algorithm to recognize areas that have acted as resistance during one period and as support during another.
The significance of a level is therefore not determined by a single condition. It is based on a combination of:
repetition;
reaction quality;
recency;
cluster tightness;
historical role reversal.
📊 How Displayed Levels Are Selected
Support and resistance levels are selected independently.
Resistance levels are selected from clusters located above the current price.
Support levels are selected from clusters located below the current price.
The selection process considers:
the minimum required number of reactions;
the maximum permitted distance from the current price;
the composite cluster-quality score;
proximity to the current price;
the minimum spacing between neighboring levels.
The Proximity priority setting increases the preference given to clusters located closer to the current price.
Proximity does not replace the underlying quality score. It is added to the cluster’s base score as an additional selection factor.
The Minimum spacing setting prevents several nearly identical levels from being displayed close together.
Users can separately define the maximum number of resistance and support levels.
When fewer qualifying clusters are available, the indicator displays only the levels that meet the selected requirements rather than forcing a fixed number of lines onto the chart.
🖥 Chart Display
For every active level, the indicator displays:
the calculated center of the reaction area;
the percentage distance from the current price;
a color based on the level’s current position relative to price.
A positive percentage means that the level is above the current price.
A negative percentage means that the level is below the current price.
The percentage distance is updated dynamically as the current price changes.
Level Origin Options
From last reaction
The line begins at the most recent confirmed reaction included in the cluster.
Across chart
The line extends across the entire chart.
Users can also customize:
support and resistance colors;
line style;
line thickness;
transparency;
label position;
horizontal spacing between labels.
🔄 Why Levels May Change
Adaptive Reaction Zones is a dynamic indicator.
Whenever a new reaction is confirmed, the price clusters are recalculated.
A new reaction may:
strengthen an existing cluster;
change the calculated center of a cluster;
create a new price area;
change the ranking of previously identified areas;
cause one displayed level to be replaced by another.
The number of stored reactions is limited by the Reaction memory setting.
When older reactions move outside the selected memory limit, they are removed from the calculation.
Displayed lines should therefore not be interpreted as permanent levels that must remain unchanged on the chart.
They represent the current result of the algorithm’s analysis of the available history of confirmed price reactions.
🛠 Main Settings
Reaction Detection
Pivot confirmation
Defines the number of bars required on each side of a local reaction before it is confirmed.
Lower values increase sensitivity. Higher values select more pronounced market extremes.
Reaction memory
Defines the maximum number of recent confirmed reactions included in the calculation.
Minimum reactions
Defines the minimum number of reactions required for a price cluster to qualify as a level.
Reaction source
Selects the source used to identify reactions:
High / Low;
Candle body.
Show confirmed reactions
Displays markers for confirmed local reactions directly on the chart.
Adaptive Clustering
ATR period
Defines the ATR period used to adapt the algorithm to changing volatility.
ATR cluster width
Defines the ATR multiplier used to determine how close reactions must be to belong to the same cluster.
Market range lookback
Defines the number of bars used to calculate the broader market range.
Range cluster width
Defines the percentage of the market range used as an additional measure of cluster width.
Historical reaction weight
Controls how quickly the influence of older reactions decreases.
Lower values cause historical reactions to lose influence more rapidly.
Level Selection
Resistance levels
Defines the maximum number of displayed resistance levels.
Support levels
Defines the maximum number of displayed support levels.
Maximum distance from price
Excludes clusters located too far from the current price.
Minimum spacing
Prevents several closely positioned levels from being displayed together.
Proximity priority
Controls how strongly proximity to the current price influences the final level selection.
Premium Appearance
This section allows users to customize:
support and resistance colors;
line style;
line thickness;
line transparency;
label transparency;
label position;
spacing between labels;
the starting point of each level line.
📌 Practical Use
A conservative approach is to treat each line as the calculated center of a broader area of interest rather than as an exact price for an automatic trade entry.
When price approaches a level, traders may additionally evaluate:
candle behavior;
trend direction;
market structure;
volume;
current volatility;
the nature of the initial interaction;
a breakout and subsequent retest of the area.
To Display Fewer but More Selective Levels
Consider increasing:
Pivot confirmation;
Minimum reactions;
Minimum spacing.
To Create a More Sensitive Market Map
Consider decreasing:
Pivot confirmation;
Minimum reactions.
Higher sensitivity may also increase the number of less significant reaction areas.
For highly volatile instruments, the ATR cluster width setting may require adjustment.
For markets with broad long-term price ranges, the Range cluster width setting may have a greater influence on the calculations.
🔔 Alerts
The indicator includes two alert conditions:
price crossing above an active reaction level;
price crossing below an active reaction level.
A crossing is determined by comparing the previous bar’s closing price with the current bar’s closing price.
To receive alerts only after a candle has been confirmed, select Once Per Bar Close when creating the TradingView alert.
✨ Originality of the Method
Adaptive Reaction Zones is not a simple combination of several standard indicators.
Confirmed pivots and ATR are used only as individual components within a unified calculation process.
Pivots provide confirmed price-reaction points, while ATR allows the calculations to adapt to changing market volatility.
The core methodology follows a structured sequence:
detecting confirmed price reactions;
evaluating the quality of each reaction;
adaptively grouping nearby reactions into clusters;
weighting reactions according to their recency;
evaluating cluster tightness and historical role reversal;
calculating a composite cluster score;
selecting support and resistance levels independently;
filtering out overlapping and excessively distant levels.
The purpose of this approach is not to display every possible market extreme.
Instead, the algorithm identifies a limited number of price areas that have the highest relevance according to the combined history, quality, density, and recency of previous market reactions.
⚠️ Limitations
The indicator uses price data only and does not account for:
fundamental events;
market news;
corporate reports;
macroeconomic factors.
Confirmed pivots always appear with a delay equal to the selected Pivot confirmation value.
This delay is a necessary part of confirming a local extreme and is not a calculation error.
New reactions may change:
the composition of a cluster;
the calculated center of an area;
the ranking of a level;
the set of lines displayed on the chart.
Results may be less stable on instruments with low liquidity, large price gaps, or insufficient historical data.
A historical reaction does not mean that price will necessarily reverse from the same area in the future.
The indicator highlights algorithmically identified areas of previous price interaction, but it does not guarantee the outcome of the next interaction with a level.
Rather than plotting every local high and low, the indicator:
detects confirmed price reactions;
evaluates the quality of each reaction;
groups nearby reactions into price clusters;
ranks the resulting areas;
displays only the most relevant support and resistance levels.
The chart shows the calculated center of each identified reaction area:
🔴 Red lines represent levels above the current price.
🟢 Green lines represent levels below the current price.
Each label displays the exact level price and its percentage distance from the current market price.
🎯 Purpose of the Indicator
Adaptive Reaction Zones provides a structured map of nearby price areas that have previously generated meaningful market reactions.
The indicator can be used to:
identify nearby support and resistance areas;
measure the distance to potentially significant price levels;
plan possible profit-taking areas;
locate zones where future price behavior may require closer observation;
analyze level breakouts and potential role reversals;
create alerts for crossings of relevant price areas.
The indicator is not a standalone trading strategy and does not generate mandatory buy or sell signals.
Its purpose is to provide an objective map of historical price reactions that traders can combine with trend analysis, market structure, volume, volatility, and other forms of analysis.
⚙️ How the Algorithm Works
1. Detecting Confirmed Price Reactions
The calculation begins with confirmed local highs and lows.
Users can select one of two reaction sources:
High / Low
The algorithm analyzes the full high and low values of each candle, including its wicks.
Candle body
The algorithm uses the boundaries of the candle body and excludes the extreme wick values.
The Pivot confirmation setting determines how many bars are required on each side of a local high or low before the reaction is confirmed.
As a result, a reaction is not included in the calculations at the exact moment the extreme occurs. It is added only after subsequent bars confirm that the point was a local high or low.
A lower setting:
increases the sensitivity of the algorithm;
produces more confirmed reactions;
allows the indicator to respond to smaller local movements.
A higher setting:
selects more pronounced market extremes;
reduces the number of secondary reactions;
increases the confirmation delay.
2. Evaluating Reaction Quality
The algorithm does not treat every confirmed local high or low as equally important.
Each reaction receives an individual quality score based on two components.
Reaction Candle Structure
For a reaction from a local high, the algorithm evaluates the upper wick relative to the candle’s total range.
For a reaction from a local low, it evaluates the lower wick.
A pronounced wick may indicate that price was rejected from that area by market participants.
Subsequent Price Movement
The algorithm also measures how far price moved away from the detected extreme during the period required to confirm the reaction.
This movement is normalized using ATR, allowing reactions formed under different volatility conditions to be compared on a consistent basis.
In the final calculation, the subsequent price movement receives slightly more weight than the candle structure.
This means that an isolated or insignificant extreme receives a lower score than a reaction followed by a meaningful price move in the opposite direction.
3. Adaptive Reaction Clustering
The market rarely reacts several times at exactly the same price.
More commonly, reactions occur within the same broader price area but at slightly different values. For this reason, Adaptive Reaction Zones groups nearby reactions into adaptive price clusters.
The cluster width is not fixed. It is calculated using:
the current ATR value;
the market range over the selected lookback period;
the instrument’s minimum tick size.
The algorithm compares the width calculated from ATR with a percentage of the broader market range and uses the larger value.
This allows the clustering distance to adapt automatically to:
current volatility;
the scale of movement in the selected instrument;
the characteristics of the market and timeframe.
ATR is not used as a separate trading signal in this indicator. It is used to normalize volatility, determine the adaptive cluster width, and calculate the minimum spacing between displayed levels.
4. Calculating the Center of a Price Area
When a new reaction is confirmed, the algorithm searches for the nearest suitable cluster.
If the distance to an existing cluster is within the calculated tolerance, the reaction is added to that cluster.
If no suitable cluster exists, a new price area is created.
The center of each cluster is calculated as a weighted average of all reactions included in it.
More recent reactions receive greater weight. The influence of older reactions gradually decreases according to the Historical reaction weight setting.
For each cluster, the algorithm stores:
the number of reactions;
the combined reaction-quality value;
the upper and lower boundaries of the area;
the bar of the most recent reaction;
the number of reactions from local highs;
the number of reactions from local lows.
🧠 How Level Significance Is Evaluated
After the clusters have been created, each cluster receives a composite score.
The score is based on five main characteristics.
Number of Reactions
The more confirmed reactions that have occurred within the same price area, the higher its base significance.
Reaction Quality
Clusters containing pronounced candle rejections and stronger subsequent price movements receive a higher score.
Recency
Recent reactions receive more weight than areas that have not interacted with price for a long time.
Cluster Tightness
Reactions concentrated within a relatively narrow price range receive a higher score than reactions spread across a wider area.
Role Reversal
A cluster receives additional weight when the same price area has generated reactions from both local highs and local lows.
This allows the algorithm to recognize areas that have acted as resistance during one period and as support during another.
The significance of a level is therefore not determined by a single condition. It is based on a combination of:
repetition;
reaction quality;
recency;
cluster tightness;
historical role reversal.
📊 How Displayed Levels Are Selected
Support and resistance levels are selected independently.
Resistance levels are selected from clusters located above the current price.
Support levels are selected from clusters located below the current price.
The selection process considers:
the minimum required number of reactions;
the maximum permitted distance from the current price;
the composite cluster-quality score;
proximity to the current price;
the minimum spacing between neighboring levels.
The Proximity priority setting increases the preference given to clusters located closer to the current price.
Proximity does not replace the underlying quality score. It is added to the cluster’s base score as an additional selection factor.
The Minimum spacing setting prevents several nearly identical levels from being displayed close together.
Users can separately define the maximum number of resistance and support levels.
When fewer qualifying clusters are available, the indicator displays only the levels that meet the selected requirements rather than forcing a fixed number of lines onto the chart.
🖥 Chart Display
For every active level, the indicator displays:
the calculated center of the reaction area;
the percentage distance from the current price;
a color based on the level’s current position relative to price.
A positive percentage means that the level is above the current price.
A negative percentage means that the level is below the current price.
The percentage distance is updated dynamically as the current price changes.
Level Origin Options
From last reaction
The line begins at the most recent confirmed reaction included in the cluster.
Across chart
The line extends across the entire chart.
Users can also customize:
support and resistance colors;
line style;
line thickness;
transparency;
label position;
horizontal spacing between labels.
🔄 Why Levels May Change
Adaptive Reaction Zones is a dynamic indicator.
Whenever a new reaction is confirmed, the price clusters are recalculated.
A new reaction may:
strengthen an existing cluster;
change the calculated center of a cluster;
create a new price area;
change the ranking of previously identified areas;
cause one displayed level to be replaced by another.
The number of stored reactions is limited by the Reaction memory setting.
When older reactions move outside the selected memory limit, they are removed from the calculation.
Displayed lines should therefore not be interpreted as permanent levels that must remain unchanged on the chart.
They represent the current result of the algorithm’s analysis of the available history of confirmed price reactions.
🛠 Main Settings
Reaction Detection
Pivot confirmation
Defines the number of bars required on each side of a local reaction before it is confirmed.
Lower values increase sensitivity. Higher values select more pronounced market extremes.
Reaction memory
Defines the maximum number of recent confirmed reactions included in the calculation.
Minimum reactions
Defines the minimum number of reactions required for a price cluster to qualify as a level.
Reaction source
Selects the source used to identify reactions:
High / Low;
Candle body.
Show confirmed reactions
Displays markers for confirmed local reactions directly on the chart.
Adaptive Clustering
ATR period
Defines the ATR period used to adapt the algorithm to changing volatility.
ATR cluster width
Defines the ATR multiplier used to determine how close reactions must be to belong to the same cluster.
Market range lookback
Defines the number of bars used to calculate the broader market range.
Range cluster width
Defines the percentage of the market range used as an additional measure of cluster width.
Historical reaction weight
Controls how quickly the influence of older reactions decreases.
Lower values cause historical reactions to lose influence more rapidly.
Level Selection
Resistance levels
Defines the maximum number of displayed resistance levels.
Support levels
Defines the maximum number of displayed support levels.
Maximum distance from price
Excludes clusters located too far from the current price.
Minimum spacing
Prevents several closely positioned levels from being displayed together.
Proximity priority
Controls how strongly proximity to the current price influences the final level selection.
Premium Appearance
This section allows users to customize:
support and resistance colors;
line style;
line thickness;
line transparency;
label transparency;
label position;
spacing between labels;
the starting point of each level line.
📌 Practical Use
A conservative approach is to treat each line as the calculated center of a broader area of interest rather than as an exact price for an automatic trade entry.
When price approaches a level, traders may additionally evaluate:
candle behavior;
trend direction;
market structure;
volume;
current volatility;
the nature of the initial interaction;
a breakout and subsequent retest of the area.
To Display Fewer but More Selective Levels
Consider increasing:
Pivot confirmation;
Minimum reactions;
Minimum spacing.
To Create a More Sensitive Market Map
Consider decreasing:
Pivot confirmation;
Minimum reactions.
Higher sensitivity may also increase the number of less significant reaction areas.
For highly volatile instruments, the ATR cluster width setting may require adjustment.
For markets with broad long-term price ranges, the Range cluster width setting may have a greater influence on the calculations.
🔔 Alerts
The indicator includes two alert conditions:
price crossing above an active reaction level;
price crossing below an active reaction level.
A crossing is determined by comparing the previous bar’s closing price with the current bar’s closing price.
To receive alerts only after a candle has been confirmed, select Once Per Bar Close when creating the TradingView alert.
✨ Originality of the Method
Adaptive Reaction Zones is not a simple combination of several standard indicators.
Confirmed pivots and ATR are used only as individual components within a unified calculation process.
Pivots provide confirmed price-reaction points, while ATR allows the calculations to adapt to changing market volatility.
The core methodology follows a structured sequence:
detecting confirmed price reactions;
evaluating the quality of each reaction;
adaptively grouping nearby reactions into clusters;
weighting reactions according to their recency;
evaluating cluster tightness and historical role reversal;
calculating a composite cluster score;
selecting support and resistance levels independently;
filtering out overlapping and excessively distant levels.
The purpose of this approach is not to display every possible market extreme.
Instead, the algorithm identifies a limited number of price areas that have the highest relevance according to the combined history, quality, density, and recency of previous market reactions.
⚠️ Limitations
The indicator uses price data only and does not account for:
fundamental events;
market news;
corporate reports;
macroeconomic factors.
Confirmed pivots always appear with a delay equal to the selected Pivot confirmation value.
This delay is a necessary part of confirming a local extreme and is not a calculation error.
New reactions may change:
the composition of a cluster;
the calculated center of an area;
the ranking of a level;
the set of lines displayed on the chart.
Results may be less stable on instruments with low liquidity, large price gaps, or insufficient historical data.
A historical reaction does not mean that price will necessarily reverse from the same area in the future.
The indicator highlights algorithmically identified areas of previous price interaction, but it does not guarantee the outcome of the next interaction with a level.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
Trading tools by MarketStructureLab. Professional indicators, algorithms & market structure logic. Get access: marketstructurelab.com
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
Trading tools by MarketStructureLab. Professional indicators, algorithms & market structure logic. Get access: marketstructurelab.com
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.