OPEN-SOURCE SCRIPT

Basic Supply & Demand Zones

1 072
This indicator draws horizontal supply and demand zones based on swing highs/lows (pivots), using a very simplified version of classic supply/demand zone logic:

Supply zones (red) → areas where strong selling supposedly happened
Demand zones (green) → areas where strong buying supposedly happened

Core logic breakdown

Pivot detection

pineph = ta.pivothigh(leftBars, rightBars) // looks for swing highs
pl = ta.pivotlow (leftBars, rightBars) // looks for swing lows
Typical default settings: leftBars = 5, rightBars = 3
→ A high must be higher than 5 bars before and 3 bars after to be considered a pivot high (and vice versa for lows).

How zones are created

When a pivot high is confirmed:

It looks at the candle body (open/close) of the bar rightBars positions back (usually the 3rd bar before current)
Creates a very thin box using only the body high/low of that candle
Box color: semi-transparent red
Extends rightward 50 bars (configurable)

→ Label "S" appears above it
When a pivot low is confirmed: same logic, but green box + "D" label below

Very important — zone height is extremely narrow
The zone height = |open - close| of the pivot candle body only
→ most real supply/demand traders would consider this too narrow (many prefer wick-to-wick or 50–100% extension of the move)
Mitigation (deletion) logic — the most useful part


Supply zone (red) → gets deleted as soon as price makes a high above the top of the box
Demand zone (green) → gets deleted as soon as price makes a low below the bottom of the box

This is a classic "mitigation" or "invalidated zone" rule — once price returns into the zone and breaks the opposite side → the zone is considered "used up".
Summary – What you actually see on chart

Red horizontal boxes appearing around recent swing highs (very thin = body only)
Green horizontal boxes appearing around recent swing lows (very thin)
Boxes extend ~50 bars to the right
When price later strongly breaks through a zone in the aggressive direction → box disappears
Tiny "S" and "D" labels (can be turned off)

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。