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)
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.