OPEN-SOURCE SCRIPT
Basic Supply & Demand Zones

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)
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)
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.