OPEN-SOURCE SCRIPT
Aggiornato Buy/Sell Zones

Buy/Sell Zones
Overview
Buy/Sell Zones is a market structure indicator designed to identify potential shifts in directional order flow through Change of Character (CHOCH) events.
When a confirmed swing level is broken in the opposite direction of the previous structural break, the indicator creates a new:
BUY ZONE after a bullish CHOCH.
SELL ZONE after a bearish CHOCH.
Each zone includes a structure-break line, a directional range box, an entry level, projected range targets, optional confirmation filters, deviation markers, alerts, and a reference-asset HUD.
The indicator is not designed to predict every market reversal. Its purpose is to provide a structured visual framework for analyzing transitions between bullish and bearish market conditions.
Market Structure Detection
Swing highs and lows are detected using a configurable fractal length.
The default Fractal Length is 12. A higher value produces fewer but more significant structural levels, while a lower value reacts more quickly to short-term price action.
A structure break can be confirmed in two ways:
Close Beyond Level: The candle must close beyond the swing level.
Wick Beyond Level: The candle only needs to trade beyond the swing level.
Requiring a candle close generally produces fewer and more conservative signals.
CHOCH Logic
The indicator tracks the direction of the most recent structural break.
A bullish break following a bearish structural state creates a BUY ZONE.
A bearish break following a bullish structural state creates a SELL ZONE.
Repeated breaks in the same direction update the structural state but do not automatically create another CHOCH zone.
BUY and SELL Zone Boxes
The directional boxes are designed to display the complete price range between the originating structure level and the candle that breaks it.
BUY ZONE Box
For a bullish structure break:
The left edge begins at the pivot-high candle.
The right edge ends after the candle that breaks the pivot high.
The upper boundary is the broken pivot-high level.
The lower boundary is the lowest wick formed between the pivot and the breakout candle.
The box uses the bullish color scheme.
SELL ZONE Box
For a bearish structure break:
The left edge begins at the pivot-low candle.
The right edge ends after the candle that breaks the pivot low.
The lower boundary is the broken pivot-low level.
The upper boundary is the highest wick formed between the pivot and the breakdown candle.
The box uses the bearish color scheme.
The box borders use a dotted style to keep the zones visible without making the chart excessively heavy.
Structure Lines and Zone Labels
Every accepted zone includes a directional line connecting the originating pivot to the structure-breaking candle.
BUY ZONE: Green structure line with the label positioned above it.
SELL ZONE: Red structure line with the label positioned below it.
The label is placed near the time-based midpoint of the structure line.
The Zone Label Distance (ATR) setting controls the vertical distance between the label and the line. Because the distance is normalized with ATR, the label placement adapts to different assets, prices, and volatility conditions.
Entry Level
The midpoint of the CHOCH signal candle’s range is treated as a potential entry reference.
Bullish CHOCH midpoint: LONG ENTRY LEVEL
Bearish CHOCH midpoint: SHORT ENTRY LEVEL
This is a reference level rather than an automatic trade signal. Traders may combine it with retests, lower-timeframe confirmation, volume behavior, candle structure, or their own risk-management model.
Range Projection Levels
The signal candle’s full high-to-low range is used as the projection unit.
The indicator initially displays:
+0.5
+1
+1.5
+2
+3
+4
-0.5
-1
-1.5
-2
-3
-4
These levels can be used as potential reaction areas, expansion targets, profit-management references, or invalidation zones.
Automatic Long-Trend Expansion
To support extended directional moves, additional levels are activated automatically:
When price trades above +4, the indicator reveals +5, +6, +7, and +8.
When price trades below -4, the indicator reveals -5, -6, -7, and -8.
The additional levels remain hidden until the corresponding +4 or -4 boundary is crossed.
Optional Filters
All filters are optional and can be enabled independently.
VWAP Direction Filter

When enabled:
BUY ZONE creation requires price to close above the session VWAP.
SELL ZONE creation requires price to close below the session VWAP.
The VWAP line can be displayed separately.
EMA Trend Filter
The EMA filter is disabled by default, with a default length of 20.

When enabled:
BUY ZONE creation requires price to be above the EMA.
SELL ZONE creation requires price to be below the EMA.
Relative Volume Filter
This filter compares current volume with average volume.
A zone is rejected when current volume is below the selected multiple of its moving average.
This can help remove structure breaks that occur during relatively weak participation. It may be less useful on instruments that do not provide reliable centralized volume data.
ATR Zone-Size Filter
The signal candle’s range is normalized against ATR.
Zones can be rejected when their signal candles are:
Too small relative to current volatility.
Excessively large relative to current volatility.
This helps prevent unusually narrow or highly extended candles from generating unwanted zones.
Confirmed-Bar Filter
When enabled, a zone is created only after the structure-breaking candle has closed.
This reduces intrabar signal changes and is particularly useful for alerts.
Minimum Bars Between Zones
A configurable cooldown can be applied between accepted CHOCH zones.
This is useful for reducing clustered signals during sideways or highly volatile conditions.
Return-to-Range Detection
The indicator can monitor price movement beyond the outer +4 and -4 boundaries.
If price trades above +4 and later closes back inside the active range, a bearish return-to-range event is detected.
If price trades below -4 and later closes back inside the active range, a bullish return-to-range event is detected.
The visual marker is disabled by default and can be enabled from the Deviation Marker settings.
Return-to-range detection does not automatically imply a reversal. It identifies a possible failed expansion or deviation that may require additional confirmation.
Reference Asset Zone HUD
The indicator includes a configurable HUD that tracks the latest structural zone of another asset on the current chart timeframe.
The HUD displays:
Selected reference asset.
Reference asset’s current BUY or SELL zone.
Mapped signal for the chart.
Current timeframe.
Direct or inverse mapping mode.
The HUD size can be set to:
Tiny
Small
Normal
Large
The default size is Normal.
Why Is USDT Dominance the Default Reference?
The default reference symbol is:
CRYPTOCAP:USDT.D
USDT Dominance represents the percentage of the total cryptocurrency market capitalization held in Tether.
It is commonly monitored as a broad crypto risk-flow reference:
Rising USDT.D can indicate that capital is moving toward stablecoins and away from risk assets.
Falling USDT.D can indicate that capital is rotating from stablecoins into cryptocurrencies.
For this reason, the HUD uses inverse mapping by default:
USDT.D BUY ZONE → Chart SELL ZONE
USDT.D SELL ZONE → Chart BUY ZONE
For example, when analyzing BTC, ETH, or another cryptocurrency, a bullish structural state in USDT.D may represent defensive capital flow and therefore map to a bearish signal for the crypto chart.
This relationship is not constant and can weaken or temporarily reverse. The reference HUD should be used as contextual confirmation rather than as an independent entry system.
Reference Ideas for Other Markets
Any TradingView-supported symbol can be selected as the HUD reference asset.
Gold Traders
Gold traders may consider monitoring:
TVC:DXY — U.S. Dollar Index
TVC:US10Y — U.S. 10-Year Treasury Yield
A directly related gold instrument or futures contract
Gold frequently has an inverse relationship with the U.S. dollar. Therefore, traders using DXY as the reference may prefer inverse mapping:
DXY BUY ZONE → Gold SELL bias
DXY SELL ZONE → Gold BUY bias
Treasury yields can also affect gold, but the relationship may change depending on inflation expectations, real yields, monetary policy, and risk sentiment.
Nasdaq Traders
Nasdaq traders may consider:
CBOE:VIX — Volatility Index
TVC:US10Y — U.S. 10-Year Treasury Yield
TVC:DXY — U.S. Dollar Index
NASDAQ:QQQ or a related Nasdaq futures symbol for direct confirmation
The VIX is generally used with inverse mapping:
VIX BUY ZONE → Nasdaq SELL bias
VIX SELL ZONE → Nasdaq BUY bias
Higher Treasury yields can pressure growth and technology stocks, but this relationship is regime-dependent. DXY may also influence risk assets and multinational technology companies, although it should not be treated as a fixed inverse signal.
When using a positively correlated reference asset, disable Invert Reference Signal to use direct mapping.
Alerts
The indicator provides three optional alert conditions:
BUY Zone Created
Triggered when a new BUY ZONE passes all enabled filters and is created.
SELL Zone Created
Triggered when a new SELL ZONE passes all enabled filters and is created.
Price Returning to Range
Triggered when price trades beyond +4 or -4 and subsequently closes back inside the active range.
Each alert can be enabled or disabled independently from the indicator settings.
After enabling an alert option, create the corresponding alert through TradingView’s alert dialog. Using Once Per Bar Close is recommended when confirmed signals are preferred.
Important Usage Notes
Pivot-based market structure requires future bars to confirm a swing. Signals are therefore intentionally delayed by the selected pivot strength.
Confirmed historical pivots do not change after confirmation.
Break conditions can change during a live candle when the confirmed-bar filter is disabled.
The reference HUD uses the chart timeframe.
Relationships between markets are dynamic and may change across volatility, liquidity, macroeconomic, and monetary-policy regimes.
Enabling multiple strict filters can significantly reduce the number of zones.
The indicator does not calculate position size, stop loss, risk-to-reward, commission, slippage, or portfolio exposure.
Disclaimer
This indicator is provided for informational and educational purposes only. It does not constitute financial, investment, trading, or legal advice and should not be interpreted as a recommendation to buy or sell any asset. Market structure signals, projected levels, reference-asset relationships, and inverse correlations can fail or change without warning. Historical performance and visual examples do not guarantee future results. Always perform your own research, confirm signals independently, use appropriate risk management, and consult a qualified financial professional before making trading or investment decisions. The user assumes full responsibility for all trading decisions, profits, and losses.
Overview
Buy/Sell Zones is a market structure indicator designed to identify potential shifts in directional order flow through Change of Character (CHOCH) events.
When a confirmed swing level is broken in the opposite direction of the previous structural break, the indicator creates a new:
BUY ZONE after a bullish CHOCH.
SELL ZONE after a bearish CHOCH.
Each zone includes a structure-break line, a directional range box, an entry level, projected range targets, optional confirmation filters, deviation markers, alerts, and a reference-asset HUD.
The indicator is not designed to predict every market reversal. Its purpose is to provide a structured visual framework for analyzing transitions between bullish and bearish market conditions.
Market Structure Detection
Swing highs and lows are detected using a configurable fractal length.
The default Fractal Length is 12. A higher value produces fewer but more significant structural levels, while a lower value reacts more quickly to short-term price action.
A structure break can be confirmed in two ways:
Close Beyond Level: The candle must close beyond the swing level.
Wick Beyond Level: The candle only needs to trade beyond the swing level.
Requiring a candle close generally produces fewer and more conservative signals.
CHOCH Logic
The indicator tracks the direction of the most recent structural break.
A bullish break following a bearish structural state creates a BUY ZONE.
A bearish break following a bullish structural state creates a SELL ZONE.
Repeated breaks in the same direction update the structural state but do not automatically create another CHOCH zone.
BUY and SELL Zone Boxes
The directional boxes are designed to display the complete price range between the originating structure level and the candle that breaks it.
BUY ZONE Box
For a bullish structure break:
The left edge begins at the pivot-high candle.
The right edge ends after the candle that breaks the pivot high.
The upper boundary is the broken pivot-high level.
The lower boundary is the lowest wick formed between the pivot and the breakout candle.
The box uses the bullish color scheme.
SELL ZONE Box
For a bearish structure break:
The left edge begins at the pivot-low candle.
The right edge ends after the candle that breaks the pivot low.
The lower boundary is the broken pivot-low level.
The upper boundary is the highest wick formed between the pivot and the breakdown candle.
The box uses the bearish color scheme.
The box borders use a dotted style to keep the zones visible without making the chart excessively heavy.
Structure Lines and Zone Labels
Every accepted zone includes a directional line connecting the originating pivot to the structure-breaking candle.
BUY ZONE: Green structure line with the label positioned above it.
SELL ZONE: Red structure line with the label positioned below it.
The label is placed near the time-based midpoint of the structure line.
The Zone Label Distance (ATR) setting controls the vertical distance between the label and the line. Because the distance is normalized with ATR, the label placement adapts to different assets, prices, and volatility conditions.
Entry Level
The midpoint of the CHOCH signal candle’s range is treated as a potential entry reference.
Bullish CHOCH midpoint: LONG ENTRY LEVEL
Bearish CHOCH midpoint: SHORT ENTRY LEVEL
This is a reference level rather than an automatic trade signal. Traders may combine it with retests, lower-timeframe confirmation, volume behavior, candle structure, or their own risk-management model.
Range Projection Levels
The signal candle’s full high-to-low range is used as the projection unit.
The indicator initially displays:
+0.5
+1
+1.5
+2
+3
+4
-0.5
-1
-1.5
-2
-3
-4
These levels can be used as potential reaction areas, expansion targets, profit-management references, or invalidation zones.
Automatic Long-Trend Expansion
To support extended directional moves, additional levels are activated automatically:
When price trades above +4, the indicator reveals +5, +6, +7, and +8.
When price trades below -4, the indicator reveals -5, -6, -7, and -8.
The additional levels remain hidden until the corresponding +4 or -4 boundary is crossed.
Optional Filters
All filters are optional and can be enabled independently.
VWAP Direction Filter
When enabled:
BUY ZONE creation requires price to close above the session VWAP.
SELL ZONE creation requires price to close below the session VWAP.
The VWAP line can be displayed separately.
EMA Trend Filter
The EMA filter is disabled by default, with a default length of 20.
When enabled:
BUY ZONE creation requires price to be above the EMA.
SELL ZONE creation requires price to be below the EMA.
Relative Volume Filter
This filter compares current volume with average volume.
A zone is rejected when current volume is below the selected multiple of its moving average.
This can help remove structure breaks that occur during relatively weak participation. It may be less useful on instruments that do not provide reliable centralized volume data.
ATR Zone-Size Filter
The signal candle’s range is normalized against ATR.
Zones can be rejected when their signal candles are:
Too small relative to current volatility.
Excessively large relative to current volatility.
This helps prevent unusually narrow or highly extended candles from generating unwanted zones.
Confirmed-Bar Filter
When enabled, a zone is created only after the structure-breaking candle has closed.
This reduces intrabar signal changes and is particularly useful for alerts.
Minimum Bars Between Zones
A configurable cooldown can be applied between accepted CHOCH zones.
This is useful for reducing clustered signals during sideways or highly volatile conditions.
Return-to-Range Detection
The indicator can monitor price movement beyond the outer +4 and -4 boundaries.
If price trades above +4 and later closes back inside the active range, a bearish return-to-range event is detected.
If price trades below -4 and later closes back inside the active range, a bullish return-to-range event is detected.
The visual marker is disabled by default and can be enabled from the Deviation Marker settings.
Return-to-range detection does not automatically imply a reversal. It identifies a possible failed expansion or deviation that may require additional confirmation.
Reference Asset Zone HUD
The indicator includes a configurable HUD that tracks the latest structural zone of another asset on the current chart timeframe.
The HUD displays:
Selected reference asset.
Reference asset’s current BUY or SELL zone.
Mapped signal for the chart.
Current timeframe.
Direct or inverse mapping mode.
The HUD size can be set to:
Tiny
Small
Normal
Large
The default size is Normal.
Why Is USDT Dominance the Default Reference?
The default reference symbol is:
CRYPTOCAP:USDT.D
USDT Dominance represents the percentage of the total cryptocurrency market capitalization held in Tether.
It is commonly monitored as a broad crypto risk-flow reference:
Rising USDT.D can indicate that capital is moving toward stablecoins and away from risk assets.
Falling USDT.D can indicate that capital is rotating from stablecoins into cryptocurrencies.
For this reason, the HUD uses inverse mapping by default:
USDT.D BUY ZONE → Chart SELL ZONE
USDT.D SELL ZONE → Chart BUY ZONE
For example, when analyzing BTC, ETH, or another cryptocurrency, a bullish structural state in USDT.D may represent defensive capital flow and therefore map to a bearish signal for the crypto chart.
This relationship is not constant and can weaken or temporarily reverse. The reference HUD should be used as contextual confirmation rather than as an independent entry system.
Reference Ideas for Other Markets
Any TradingView-supported symbol can be selected as the HUD reference asset.
Gold Traders
Gold traders may consider monitoring:
TVC:DXY — U.S. Dollar Index
TVC:US10Y — U.S. 10-Year Treasury Yield
A directly related gold instrument or futures contract
Gold frequently has an inverse relationship with the U.S. dollar. Therefore, traders using DXY as the reference may prefer inverse mapping:
DXY BUY ZONE → Gold SELL bias
DXY SELL ZONE → Gold BUY bias
Treasury yields can also affect gold, but the relationship may change depending on inflation expectations, real yields, monetary policy, and risk sentiment.
Nasdaq Traders
Nasdaq traders may consider:
CBOE:VIX — Volatility Index
TVC:US10Y — U.S. 10-Year Treasury Yield
TVC:DXY — U.S. Dollar Index
NASDAQ:QQQ or a related Nasdaq futures symbol for direct confirmation
The VIX is generally used with inverse mapping:
VIX BUY ZONE → Nasdaq SELL bias
VIX SELL ZONE → Nasdaq BUY bias
Higher Treasury yields can pressure growth and technology stocks, but this relationship is regime-dependent. DXY may also influence risk assets and multinational technology companies, although it should not be treated as a fixed inverse signal.
When using a positively correlated reference asset, disable Invert Reference Signal to use direct mapping.
Alerts
The indicator provides three optional alert conditions:
BUY Zone Created
Triggered when a new BUY ZONE passes all enabled filters and is created.
SELL Zone Created
Triggered when a new SELL ZONE passes all enabled filters and is created.
Price Returning to Range
Triggered when price trades beyond +4 or -4 and subsequently closes back inside the active range.
Each alert can be enabled or disabled independently from the indicator settings.
After enabling an alert option, create the corresponding alert through TradingView’s alert dialog. Using Once Per Bar Close is recommended when confirmed signals are preferred.
Important Usage Notes
Pivot-based market structure requires future bars to confirm a swing. Signals are therefore intentionally delayed by the selected pivot strength.
Confirmed historical pivots do not change after confirmation.
Break conditions can change during a live candle when the confirmed-bar filter is disabled.
The reference HUD uses the chart timeframe.
Relationships between markets are dynamic and may change across volatility, liquidity, macroeconomic, and monetary-policy regimes.
Enabling multiple strict filters can significantly reduce the number of zones.
The indicator does not calculate position size, stop loss, risk-to-reward, commission, slippage, or portfolio exposure.
Disclaimer
This indicator is provided for informational and educational purposes only. It does not constitute financial, investment, trading, or legal advice and should not be interpreted as a recommendation to buy or sell any asset. Market structure signals, projected levels, reference-asset relationships, and inverse correlations can fail or change without warning. Historical performance and visual examples do not guarantee future results. Always perform your own research, confirm signals independently, use appropriate risk management, and consult a qualified financial professional before making trading or investment decisions. The user assumes full responsibility for all trading decisions, profits, and losses.
Note di rilascio
repaired hud bug.Note di rilascio
!!fixed alerts !!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.
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.
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.