OPEN-SOURCE SCRIPT
Updated

S/R & S/D Zone Pro

3 424
S/R & S/D Zone Pro

SD Zone Pro is an advanced concept indicator that identifies Supply and Demand zones using pivot points, clustering, and volume weighting. It is designed to reduce chart clutter, dynamically track zones, and visualize the interaction of historical zones with current price action.


🎯 Use as Support and Resistance

Demand Zones → Support Levels: The green/red demand boxes formed on the chart represent potential Support areas where buyers are concentrated and price drops may halt or bounce upward. When price retraces to these zones, potential reversal signals or buying opportunities can be monitored.

Supply Zones → Resistance Levels: The supply boxes formed around peak areas represent potential Resistance areas where sellers gain control and upward price movement may be capped. When price approaches these levels, profit-taking or downward reaction signals can be watched.

Zone Breakouts and Role Reversals (Flip Zones): If a supply (resistance) zone is broken upward with strong volume, it can act as support when price retraces back to it in the future. Similarly, when a demand (support) zone is broken downward, it may serve as resistance going forward.

Tolerance and Volume Confirmation: Unlike single-line support/resistance levels, this indicator presents price levels as ranges/boxes and displays pivot volume, providing a more reliable wide-band support and resistance framework.


📏 Box Width (Zone Height / Thickness), Volume Impact, and Usage

Dynamic ATR Structure: The vertical width (height) of the boxes is automatically calculated using the ATR (Average True Range) metric in line with market volatility.

Meaning of Zone Thickness:

Wide/Thick Boxes: Formed during periods of high volatility or across wider pivot clusters. Indicates a broader buffer zone where price may fluctuate inside the area.

Narrow/Thin Boxes: Formed during low volatility or when price reacts to very precise levels. These areas highlight cleaner and sharper support/resistance zones.


Volume Impact on Zones:

Accumulation and Validity Confirmation: Independent of box width, the total volume (K, M, B) accumulated over a zone directly defines its strength. High volume inside a narrow box indicates a major institutional battle (accumulation/distribution) took place within that tight band, making it a very strong barrier.

Zone Merging and Volume Compounding: When adjacent boxes merge (either same-side or cross-side supply/demand overlaps), the height and coverage of the new combined zone expand while the accumulated volumes of all merged zones are summed up on the label. This confirms that the widened box has evolved into a high-volume Major Zone.


Usage in Trading and Risk Management:

Stop-Loss Placement: Ideal stop-loss levels should be placed slightly beyond the outer boundary of the box rather than right at the top/bottom edge, accounting for box width (thickness) to avoid false breakouts (fakeouts).

Entry and Confirmation Levels: Since the box width represents a price range, entries closer to the middle or opposite boundary of the box offer a more favorable Risk/Reward ratio. Reactions from high-volume zones increase trade probability.


📐 Box Extension Logic

1. Extension of Active (Unclosed) Boxes

The latest supply and demand boxes that are still forming and have not yet been absorbed by a merge are automatically extended from their right edge to the current bar as new bars develop.

The volume labels attached to these boxes also follow this alignment, updating their position to the right on every new bar.

2. Extension of Closed (Historical) Boxes
Whether historical zones extend to the current bar depends on the selected mode:

Continuous Extension Mode (Unrestricted):
When proximity filtering is turned off, the right edge of all historical supply and demand boxes continues to extend to the end of the chart on every new bar.

Price Proximity Extension Mode:
When enabled, box extension relies on three specific rules:

Direct Touch or Proximity: When price enters a box's price range or comes within the configured percentage proximity tolerance, the right edge of that box extends to the current bar. If price moves away, the box remains fixed at the last bar it touched.

Tracking Nearest Zones to Price: Even if price does not directly touch the boxes, the 2 nearest boxes strictly above and the 2 nearest boxes strictly below the current close price are continuously identified. As price moves, these nearest levels are re-evaluated, and these 4 boxes dynamically extend to the current bar regardless of touch criteria.

Exemption for Recent Zones: The newest closed boxes within the defined box limit are exempt from the touch condition and always remain extended to the current bar.

3. Price Range Filter and Visibility Logic

Boxes outside the specified minimum/maximum price limits continue running their extension logic in the background; however, their background and border opacities are set to 100% transparent to hide them from the chart. The price range filter does not stop boxes from extending; it only controls their visual display on screen.


📌 How to Use

Zone Formation: The indicator monitors swing lows (Pivot Low) and swing highs (Pivot High) on the chart. Once your specified grouping numbers are met, it automatically constructs Demand (Green/Red boxes) or Supply zones.

Volume Insights: The right side of each zone displays the total volume (formatted in K, M, B) of the pivot bars forming that cluster.

Live Tracking and Extension: From the moment zones form, their right edges extend toward the current bar.

Touch and Proximity Tracking: When price approaches or touches a historical zone again, that zone reactivates and extends toward the current bar.

Multi-Timeframe (MTF): You can project supply and demand zones from higher timeframes (e.g., 4-Hour, Daily) directly onto your lower timeframe charts.


⚙️ Settings and Definitions

1. Grouped Pivot Volume & SD Zones (Main Calculation & Clustering)

Show Demand / Supply Labels?: Toggles volume labels on or off in the Demand and Supply zones.

ATR Multiplier (Box Merge Tolerance): Defines the merge tolerance for closely formed boxes. The ATR value is multiplied by this factor; boxes separated by less than this distance are merged into a single zone.

Merge Supply & Demand Overlaps?: When enabled, overlapping Supply and Demand zones (within price tolerance) merge into a single zone.

Enable Merged Zone Color & Merged Zone Color: Highlights zones formed by a cross-merge between Supply and Demand with a distinct custom color (default: Orange).

Display Mode: Select whether to display Demand Only, Supply Only, or Both zone types on the chart.

Show Last (Non-Merged) Box?: The master switch controlling the visibility of the most recent active box that hasn't been merged yet.

Extend Boxes Only on Price Proximity?:

OFF: All historical boxes extend continuously to the latest bar.

ON: Boxes extend to the latest bar only when price approaches/touches them or when they are among the nearest zones to price.

Proximity Tolerance (%): Specifies how close (in percentage) price must get to a box level to trigger an extension.

2. Price Range Filter

Enable Price Range Filter?: Hides boxes that fall outside the specified lower and upper price limits.

Min Price / Max Price: The minimum and maximum price boundaries within which boxes remain visible.

3. Multi-Timeframe (MTF)

Enable MTF?: Enables pulling data from a different timeframe.

MTF Timeframe: The timeframe used for pivot detection (e.g., 1D, 4H, 1H). If left blank, the chart's current timeframe is used.

⚠️ IMPORTANT NOTES & DISCLAIMERS

💡 Regarding Repainting:
Pivot-based indicators inherently require confirmation bars defined by Pivot Length. Once a pivot is confirmed, the box is plotted back in history. This is not a bug or error; it is the fundamental technical mechanism of pivot calculations.

💡 MTF Usage:
When using Multi-Timeframe (MTF) mode, it is highly recommended to select a higher timeframe than your chart's current timeframe (e.g., 1-Hour or 4-Hour MTF while viewing a 15-minute chart). Selecting lower timeframes may cause data misalignment or missing bar mappings.

💡 Performance and Engine Limits:
Due to Pine Script engine limits, a maximum of 500 boxes and labels can be rendered simultaneously on a chart. The indicator features automatic capacity management to prevent memory overflow errors.
Release Notes
Several minor bugs were fixed and a few settings were added.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.