OPEN-SOURCE SCRIPT

Supply and Demand Zones | Flux Charts

20 427
GENERAL OVERVIEW
Supply and Demand Zones indicator uses a simple but effective mechanism to find the most useful supply and demand zones on any chart. Most tools draw every zone they can find and leave the trader to sort through the clutter. This indicator does the opposite: it watches how price actually behaves at each zone and keeps only the levels that have earned attention.

The mechanism is straightforward. Each zone is built from a confirmed price swing, and from that moment it is tracked as a living object. Every time price returns, the indicator records what happened — a clean rejection (retest), a failed push-through that snaps back (also a retest), or a decisive break. From that record it computes one honest number, Held: the share of retests where the zone successfully pushed price away. A zone that has held four of five tests is immediately separated from one that keeps breaking.

That same track record then drives what you see. Instead of showing every zone, the indicator surfaces a small set of the most useful ones — ranked by how reliably they have held, how often they have been tested, and how close they are to current price. The result is a clean chart focused on the zones that have actually proven themselves, rather than a wall of boxes you have to filter by eye.

لقطة

WHAT IS THE THEORY BEHIND THE INDICATOR?
Supply and demand trading is built on a simple idea: where price reversed sharply once, it often reacts again, because unfilled orders and trapped traders remain at that level. The problem is that not every zone is equal. Some levels are respected again and again; others break the first time they are tested. Most supply and demand tools draw every zone the same way and leave the trader to guess which ones still matter.

This indicator takes the position that a zone's history is more informative than its existence. A level that has been tested five times and held four of them is telling you something a fresh, untested level cannot. So instead of treating zones as static boxes, the indicator watches every interaction — bounces, failed breakouts, and clean breaks — and turns that record into a measurable hold rate. A zone earns its place on your chart by performing, not just by existing.

لقطة

FEATURES
  • Finds the most useful zones — instead of drawing every zone, it tracks how each one behaves and surfaces only the levels that have proven themselves
  • Automatic zone detection — supply and demand zones are built from confirmed price swings, with boundaries sized by the average wick so each box covers the real reaction area
  • Per-zone track record — every zone carries its own data: how many times it has been retested, how many times it has broken, and how reliably it has held
  • Held statistic — each zone shows the share of its retests that successfully held, turning its history into one honest reliability number you can read at a glance
  • Retest tracking — every test of a zone is recorded and marked on the chart, including failed breakouts that snap back into the zone
  • Breakout & flip tracking — clean breaks are recorded, and the zone flips from supply to demand (or vice-versa) while keeping its full history
  • Strongest / Nearest ranking — shows the most useful zones, ranked by how reliably they have held, how often they have been tested, and how close they are to price
  • Clear, data-rich visuals — gradient zone fills, glowing retest markers, colour-coded flip segments, and a per-zone stats label that displays its retests, breakouts, and Held % right beside it
  • Clean-chart controls — minimum spacing hides near-duplicate zones, and a smooth fade-out dims zones as they drop off the list
  • Four alerts — retests and breakouts, on both supply and demand


ZONE DETECTION AND BOUNDARIES

What is a zone?
A zone is a price area drawn around a recent swing high or swing low. A swing high becomes a supply zone (an area sellers defended); a swing low becomes a demand zone (an area buyers defended). New zones are only created when they don't overlap an existing one, so the chart never stacks duplicate boxes on the same level.

Why does it matter?
Swings are where the market actually changed its mind, which makes them the most natural place to expect a future reaction. Building zones only from confirmed swings — and skipping overlaps — keeps the set of zones meaningful instead of cluttered. Clean, non-overlapping detection is the foundation everything else builds on: the track record and ranking are only as useful as the zones they start from.

How is it detected and calculated?
The indicator waits for a swing to confirm using the Swing Period: a high or low only counts once that many bars have printed on both sides of it. The zone's outer edge sits at the swing's extreme (the high for supply, the low for demand). The inner edge is set using the average wick of the candles around the swing, so the zone covers the real reaction area rather than a single thin line. Because a swing needs bars on both sides to confirm, each zone appears a fixed number of bars after the swing itself — a normal, non-repainting delay rather than a level that appears and disappears.

لقطة

Settings
  • Swing Period — how many bars must confirm a swing on each side before it forms a zone. Higher = fewer, more significant zones; lower = more zones that react faster to price. Default 30.
  • Lookback — how far back the indicator looks for zones, in bars. Higher keeps older zones on the chart; lower focuses on recent price action. Default 2000.


RETESTS AND FAILED BREAKOUTS

What is a retest?
A retest is when price returns to a zone, touches it, and is rejected — closing back out on the same side it came from. This is the classic supply/demand reaction: price revisits the area and the zone pushes it away. A failed breakout — price pushing through the zone but then closing back inside it — is also counted as a retest, because the zone ultimately won.

Why does it matter?
Retests are the evidence that a zone is still active. A level that keeps rejecting price is one the market is clearly watching. Counting failed breakouts as retests is important too: a level that traps breakout traders and reclaims is often the strongest kind of level, and ignoring those events would understate a zone's true strength.

How is it detected and calculated?
On each closed bar, a zone is checked for a reaction: for a supply zone, price reaching into the zone but closing back below it counts as a retest; for a demand zone, reaching in but closing back above. To avoid over-counting when price lingers at a level, a Retest Cooldown requires a minimum number of bars between two counted retests on the same zone. Separately, if price closes clean through a zone and then closes back inside it on the next resolution, that failed breakout is recorded as a retest as well. All events are evaluated only on confirmed (closed) bars, so nothing is counted on an unfinished candle.

لقطة

Settings
  • Retest Cooldown — waits this many bars before counting another test of the same zone, so price lingering at a level isn't counted as many separate retests. Default 3.
  • Retests (toggle + marker) — show or hide retest markers and choose their shape (Circle, Triangle, Cross, Diamond).


BREAKOUTS AND ZONE FLIPS

What is a breakout?
A breakout is when price closes decisively through a zone and keeps going, rather than being rejected. When a zone breaks, it flips: a broken supply zone becomes a demand zone, and a broken demand zone becomes a supply zone — the same idea as old resistance becoming new support. Crucially, the zone keeps its history through the flip; it doesn't start over.

Why does it matter?
A clean break is the opposite of a hold, and tracking it is what makes the Held statistic meaningful. The flip behaviour also reflects how these levels really work in practice — a level that breaks rarely disappears; it changes role. Keeping each zone's full history across flips means a level that has been a battleground through several cycles is shown as exactly that.

How is it detected and calculated?
When price first closes through a zone, the zone enters a pending state. The very next resolution decides what happened: if price closes through again, it is confirmed as a breakout and the zone flips its side; if price instead closes back inside, it is recorded as a failed breakout (a retest). This two-step confirmation avoids calling a breakout on a single bar that immediately reverses. Each flip also starts a new coloured time segment, so the zone's box visually records when it was supply and when it was demand across its life.

لقطة

Settings
  • Breakouts (toggle + marker) — show or hide breakout markers and choose their shape. Off by default to keep the chart clean.


THE HELD STATISTIC

What is Held?
Held is the heart of the indicator. It answers a simple question: when price comes back to this zone, how often does the zone actually hold? It is shown on each zone's stats label as a count and a percentage, for example "Held: 4 (80%)" — meaning four of the zone's five retests successfully held.

Why does it matter?
This is the number that separates a level worth trading from one that just happens to be on the chart. A high Held % means the zone has repeatedly done its job; a low one warns you the level is leaky. Because it is measured from the zone's own history rather than assumed, it gives you an honest, at-a-glance read on reliability.

How is it detected and calculated?
After each retest, the indicator looks forward over the Hold Window — a set number of candles — and checks whether the zone was broken during that window. If the zone survived the window without a breakout, that retest counts as a hold. Only retests old enough to have a full window behind them are judged, so a very recent retest doesn't distort the number before its outcome is known. Held is then the count of successful holds, shown alongside its percentage of all retests.

لقطة

Settings
  • Hold Window — after a retest, the zone must avoid a breakout for this many candles to count as a successful hold. Drives the Held stat and the Strongest ranking. Default 10.


STRONGEST AND NEAREST RANKING

What is the ranking?
Rather than crowd the chart with every zone it finds, the indicator shows a limited number per side and chooses which ones using one of two modes. Nearest simply shows the zones closest to current price. Strongest shows the zones that have most reliably held, weighted by how often they've been tested and how close they are to price.

Why does it matter?
Most charts have far more historical zones than are useful at once. Nearest is best when you care about the levels price is about to interact with regardless of their record. Strongest is best when you want the chart to surface proven levels — the ones that have repeatedly held — so your attention goes to the areas with the best track record.

How is it detected and calculated?
The Strongest score combines three things. Reliability is the zone's hold rate, but smoothed so a zone tested only once can't look perfect — its record is trusted more as it accumulates more tests. Evidence rewards zones that have been tested more often, with diminishing returns so one ancient zone doesn't dominate forever. Proximity favours zones closer to price. A small bonus is given to zones already on screen so the displayed list stays steady instead of swapping every bar. Nearest mode, by contrast, simply ranks by distance to price.

لقطة
لقطة

Settings
  • Rank By — Strongest (most reliable, weighted by tests and proximity) or Nearest (closest to price). Default Strongest.
  • Show — how many supply and how many demand zones to show at once; each side is counted separately. Default 5.


ZONE SPACING AND FADE-OUT

What are spacing and fade-out?
Two features keep the chart readable. Minimum spacing hides a zone that sits too close to one already shown, so you don't get several near-identical boxes stacked together. Fade-out smoothly dims a zone as it drops off the visible list, instead of having it vanish abruptly.

Why does it matter?
A clean chart is easier to act on. Spacing prevents visual clutter at congested levels, and the fade-out makes it obvious when a zone is no longer among the top picks without the chart jumping around distractingly.

How is it detected and calculated?
When selecting which zones to show, the indicator skips any candidate sitting within the Min Zone Spacing distance (a percentage of price) of a zone already chosen. When a previously shown zone is no longer selected, it is moved to a fade list and dimmed over a fixed number of bars before being removed. Drawing is also budgeted internally so the gradient zone fills always stay within the platform's object limits.

لقطة

Settings
  • Min Zone Spacing (%) — hides zones sitting too close to one already shown, to keep the chart clean. Set to 0 to show every zone. Default 0.1%.
  • Supply / Demand colours — the colours used for supply and demand zones, their gradient fills, and their markers.


ALERTS

What alerts are available?
  • Bullish Retest — price bounced from a demand zone.
  • Bearish Retest — price rejected from a supply zone.
  • Bullish Breakout — price broke above a supply zone.
  • Bearish Breakout — price broke below a demand zone.


When do they fire?
Each alert fires on a confirmed bar at the moment the matching event is recorded, so you are notified of bounces and breaks as they are confirmed rather than on an unfinished candle.

IMPORTANT NOTES
  • All retests, breakouts and flips are evaluated only on closed (confirmed) bars, so events are not counted on an in-progress candle.
  • A breakout requires price to close through a zone and then confirm on the next resolution. A single bar that closes through and immediately closes back in is recorded as a retest (failed breakout), not a breakout.
  • Held only judges retests that have a full Hold Window of bars behind them, so the most recent retest may not yet be reflected in the Held count until its outcome is known.
  • When a zone breaks it flips side and keeps its full history, so a single long-lived zone can show interactions from several supply/demand cycles.
  • The number of zones shown is limited per side by the Show setting; other valid zones continue to be tracked in the background and can appear later as conditions change.


UNIQUENESS
Most supply and demand indicators draw zones and stop there, leaving the trader to guess which levels still matter. Supply and Demand Zones treats each zone as a tracked object with a measurable record. Every retest, failed breakout and clean break is recorded over the zone's life, and the Held statistic turns that record into a single, honest reliability number shown right on the zone — a level that has held four of five tests is immediately distinguishable from one that keeps breaking. Failed breakouts are folded into retests rather than ignored, capturing the trap-and-reclaim behaviour that often marks the strongest levels, and broken zones flip side while keeping their entire history instead of resetting. The Strongest ranking is driven by that same measured record — reliability, number of tests, and proximity — with smoothing so a single lucky test can't masquerade as a perfect level, meaning the chart automatically surfaces the zones that have actually proven themselves. The result is a supply and demand tool that doesn't just show you where zones are, but how much each one has earned your trust.

DISCLAIMER
This indicator is an analytical and educational tool. It does not predict future price movement and does not provide financial advice. A zone's past hold rate describes what has already happened and does not guarantee future behaviour. Always use proper risk management and combine this tool with your own analysis.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.