OPEN-SOURCE SCRIPT

Supply and Demand Zones with Market Structure [Jayadev Rana]

5 035
Overview
This open-source overlay draws two closely related price-action concepts on a single chart: swing-based supply and demand zones, and market-structure mapping (swing labels, a zig-zag of confirmed swings, and Break of Structure markers). It is a visual analysis aid. It does not generate buy or sell signals, it does not place orders, and it makes no performance claim.

How swings are detected
Every element in the script is anchored to a confirmed swing pivot. Swings are found with symmetric pivots: a swing high requires its high to be the highest of the N bars on its left and the N bars on its right (and the mirror condition for a swing low), where N is the Swing High/Low Length input. Because a pivot needs N bars on both sides to exist, it is only confirmed N bars after the pivot bar. Once a swing is confirmed, its label, zone and zig-zag segment are fixed to that historical bar and do not move or repaint afterwards. The trade-off of this method is a fixed N-bar delay before a swing becomes visible. This is inherent to symmetric pivots and is disclosed here so the behavior is clear.

Supply and demand zones
When a swing high is confirmed, a supply zone is drawn from that swing high down to the top of the swing candle's body. When a swing low is confirmed, a demand zone is drawn from that swing low up to the bottom of the swing candle's body. This anchors each zone on the candle that produced the turning point. Because wick-only zones can be very thin, an optional ATR floor (on by default) gives each zone a minimum thickness equal to a configurable multiple of the 14-period ATR, so zones stay readable across different instruments and timeframes.

Each zone extends to the right until it is mitigated. A supply zone is treated as mitigated when price closes above it; a demand zone when price closes below it. On mitigation the zone is either removed or greyed out, depending on the When a zone is broken input. To respect the platform limit of 500 drawing objects and to keep the chart readable, only the newest N zones per side are retained (the Zones to keep per side input).

Market structure
Swing labels: each confirmed swing is labelled relative to the previous same-side swing. Highs are marked HH (higher high) or LH (lower high); lows are marked HL (higher low) or LL (lower low). Bullish structure (HH, HL) uses the bullish colour and bearish structure (LH, LL) uses the bearish colour.
Zig-zag: consecutive confirmed swings are joined by a line, giving a de-cluttered skeleton of price movement.
Break of Structure (BOS): the most recent confirmed swing high and swing low are tracked as reference levels. The first time price closes above the reference swing high a BOS is marked, and the mirror for a close below the reference swing low. Each level is marked only once.

Dashboard
An optional table in the top-right corner shows the current swing length, the number of active supply and demand zones, and the direction of the last Break of Structure.

Inputs
Structure and Swings: swing length, and toggles for the zig-zag, the swing labels and the BOS markers.
Supply and Demand Zones: master toggle, zones to keep per side, the ATR minimum-thickness option and multiplier, broken-zone handling (remove or grey out), and the right-extension toggle.
Colors: independent fill and border colours for supply, demand and broken zones, the zig-zag colour, and the bullish and bearish structure colours.
Dashboard: show or hide the summary table.

Alerts
Alert conditions are provided for a bullish BOS, a bearish BOS, a new supply zone, and a new demand zone.

How to use it
Supply and demand zones are commonly read as areas where price may react, while market structure (the sequence of HH, HL, LH, LL and BOS events) describes the prevailing trend and its changes. Reading the two layers together, for example a demand zone that coincides with bullish structure or a supply zone that coincides with bearish structure, is one way traders use this kind of tool. This script only draws the levels and the structure. It does not tell you when to enter or exit, and any decision you make is your own.

Originality and scope
This is an original implementation written from scratch. The underlying ideas, namely pivot-based swing detection, supply and demand zones, higher-high and lower-low structure labelling, and break of structure, are long-established public-domain price-action concepts rather than the property of any single author. The purpose of this publication is to combine them into one coherent, fully configurable, non-repainting overlay with readable code and a compact summary dashboard.

Limitations and disclaimer
Swings, and everything derived from them, appear with a fixed N-bar confirmation delay. This is by design and is not an error.
Zone mitigation is evaluated on bar close. On the developing (last) bar, states can still change until the bar closes.
Past behaviour of price around a zone or a structure point does not predict future results. This tool is for education and analysis only and is not financial advice. Test any approach yourself before relying on it.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.