OPEN-SOURCE SCRIPT
Updated

Supply & Demand Zones XL

11 996
Description

Supply & Demand Zones XL is a non-repainting supply and demand indicator designed to model market structure with a focus on stability, clarity, and quantitative strength evaluation.

The script identifies supply and demand zones using pivot-based structure and sizes each zone dynamically using ATR, ensuring consistent scaling across different market conditions. Zones are extended forward in real time and maintained as either active or historical depending on user preference.

Each zone is scored using a composite strength model that incorporates volume participation, zone width efficiency, time in market, and touch frequency. The resulting strength rating is normalized to a simple X/10 format and displayed at the end of each zone for immediate readability.

A non-repainting mode ensures that zones are only confirmed after pivot completion, preventing forward-looking bias. An optional volume filter allows users to require above-average participation before a zone is formed.

The script includes logic to prevent redundant structure by disallowing overlapping zones of the same type while the current zone remains valid. Once a zone is broken, new zones are allowed to form, preserving structural continuity.

Zones are considered broken only on confirmed closes beyond their boundaries, not intrabar wicks. Broken zones are downgraded in strength and can be visually differentiated using customizable color controls. Users can independently control coloring for active and historical broken zones, as well as define separate colors for supply, demand, broken supply, and broken demand.

Historical zones can be toggled on or off, with optional strength labels, allowing users to balance context versus chart clarity.

The result is a structured, state-driven supply and demand model that avoids noise, reduces duplication, and provides a consistent framework for evaluating zone quality and market behavior.
Release Notes
Defaults updated.
Release Notes
Added Bars Left & Bars Right user functionality.
Release Notes
Updated zone scoring logic.
Release Notes
Non-repaint logic applied to broken zones.
RSI Confirmation toggle/logic added.
Release Notes
Added triangle visuals with user toggle.
Release Notes
Added Supply/Demand Triangle Color controls.
Added Strong vs Weak Zone Color controls.
Improved Zone Strength calculation engine.
Release Notes
Internal bug fixes.
Adjusted default zone colors.
Release Notes
User input control for zone transparency added.
Release Notes
Added user input controls for zone strength.
Updated order of user input controls.
Release Notes
Updated disallow same-zone overlap logic.
Release Notes
The update changes how overlap is handled by separating same-zone and different-zone logic and narrowing the scope of each check to only the most recently accepted zone of that type. Instead of evaluating overlap against all existing zones or relying on active/broken state, a new supply zone is now only compared to the previous supply zone for same-side filtering and to the previous demand zone for opposite-side filtering. This makes zone creation more deterministic and prevents immediate duplication or direct conflict between consecutive zones, while still allowing older zones to coexist if they are not part of the most recent structural interaction.
Release Notes
This update introduces the Flow Line, a streamlined trend regime overlay that dynamically colors price action based on direction and strength using an adaptive EMA, volatility-normalized slope, and ADX filtering. It replaces multiple exposed inputs with a single Fast, Medium, or Slow speed setting, keeping the interface clean while preserving the underlying logic for identifying trending versus consolidating market conditions.
Release Notes
Internal defaults adjusted.
Release Notes
User inputs re-organized.
Release Notes
Bug fixes.
Release Notes
Internal Updates.
Release Notes
Pine category updated.
Release Notes
Internal code min/max/step data added to user inputs.
Release Notes
The zone strength scoring system has been completely rewritten from the ground up. The old engine used simple linear math across three components. The new engine uses five distinct signals, logarithmic scaling, and a configurable recency decay multiplier.

──────────────────────────────
WHAT'S NEW
──────────────────────────────

▸ Departure Velocity (new)
How fast and decisively did price leave the zone? A sharp, clean rejection scores high. A slow grind away scores low. This is the single strongest signal of genuine institutional activity at a zone origin — and the old engine had nothing like it.

▸ Zone Purity (new)
Measures the body-to-range ratio of the pivot candle. A large-bodied decisive candle = clean order flow. A doji or indecision candle = weak zone origin. Fresh zones now reflect the quality of their formation candle.

▸ Recency Decay (new)
Old zones lose relevance over time even if never broken. An exponential decay multiplier is applied to the final score with a configurable half-life (default: 100 bars). A zone from 500 bars ago that was never retested is no longer scored the same as a fresh one.

▸ Wick vs Body Touch Detection (rebuilt)
The old engine counted any price contact as a touch. The new engine distinguishes:
— Wick touch: price probed the zone but closed outside it (zone held — minor penalty)
— Body touch: close landed inside the zone (zone is being absorbed — major penalty)
Both have separate, individually weighted penalty controls.

▸ Logarithmic Scaling Throughout
Every component now uses log-based curves instead of linear math. The difference between a 5-bar-old and 50-bar-old zone is meaningful. The difference between 200 bars and 500 bars is far less so. Same principle applies to touch penalties and volume.

──────────────────────────────
NEW INPUTS ADDED
──────────────────────────────

• Departure Velocity Weight
• Zone Purity Weight
• Wick Touch Penalty Weight
• Body Touch Penalty Weight
• Use Recency Decay (toggle)
• Decay Half-Life in Bars

All existing inputs are preserved. Default weights are tuned to reflect real S&D logic out of the box.

──────────────────────────────
NOTES
──────────────────────────────

Zone scores will look different from v1 — this is expected. The new model is more selective. A score of 7+/10 now means more than it did before. Broken zones still floor at 1/10 regardless of prior score.

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.