OPEN-SOURCE SCRIPT
Supply Demand Pro - VWAP + Liquidity Confluence

Supply Demand Pro — Liquidity + VWAP Confluence
by ApexFlow
━━━━━━━━━━━━━━━━━━━━
INSPIRATION & CREDIT
━━━━━━━━━━━━━━━━━━━━
Credit: Zone base detection concept inspired by "Market Structure Break & Orderblock" by EmreKb (TradingView open-source). All code has been rewritten with significant original additions: quantitative grading system (A+/A/B/C), VWAP confluence scoring, liquidity sweep detection, multi-timeframe overlay, and live backtest panel.
━━━━━━━━━━━━━━━━━━━━
WHAT THIS INDICATOR DOES
━━━━━━━━━━━━━━━━━━━━
Detects institutional supply and demand zones using a three-layer confluence model:
1. Zone formation: explosive impulsive move + consolidation base
2. Zone scoring: quantitative grade based on move strength, volume, VWAP proximity, HTF overlap
3. Signal generation: price returns to zone with rejection confirmation + sweep detection
The combination of these three layers separates this from standard S&D indicators that draw zones without qualification.
━━━━━━━━━━━━━━━━━━━━
ZONE DETECTION METHODOLOGY
━━━━━━━━━━━━━━━━━━━━
A zone forms when a confirmed bar (barstate.isconfirmed) meets all of:
- Bar range > ATR(14) × Move Multiplier — confirms volatility expansion
- Candle body > 55% of total range — filters wicky, indecisive bars
- Optional: Volume > SMA(20) × multiplier — confirms participation
ATR uses ta.atr(14). Body percentage = |close − open| / (high − low).
The base of the zone is built from preceding candle(s) where:
- |close − open| < ATR × 0.5 (small-bodied consolidation)
- Bar is not itself explosive
Base high and low define the zone boundaries:
- Supply zone: base candle(s) before bearish explosive move
→ Top = base high, Bottom = min(base low, explosive open)
- Demand zone: base candle(s) before bullish explosive move
→ Top = max(base high, explosive open), Bottom = base low
All detection references bar[1] and bar[2] on confirmed bars only. No repainting, no lookahead.
━━━━━━━━━━━━━━━━━━━━
ZONE GRADING SYSTEM (A+ / A / B / C)
━━━━━━━━━━━━━━━━━━━━
Each zone receives a score from 0–100 at creation using four measurable factors:
Move strength (max 30 pts):
- score += min((range[1] / ATR[1]) × 18, 30)
Volume strength (max 20 pts):
- score += min((volume[1] / volAvg[1]) × 13, 20)
- If volume confirmation disabled: default 10 pts
VWAP confluence (25 pts):
- +25 if session VWAP falls within zone ± (ATR × tolerance)
- Uses ta.vwap (session-anchored)
HTF zone overlap (20 pts):
- +20 if zone price range overlaps a detected higher-timeframe zone
- HTF data pulled via request.security() with lookahead=barmerge.lookahead_off
Freshness bonus (5 pts):
- +5 at creation
Grade thresholds:
- A+ ≥ 80 | A ≥ 65 | B ≥ 50 | C < 50
Grade displayed as badge inside each zone. Signals filterable by minimum grade.
━━━━━━━━━━━━━━━━━━━━
VWAP CONFLUENCE
━━━━━━━━━━━━━━━━━━━━
Session VWAP (ta.vwap) compared to each new zone at creation:
vwapInZone = VWAP ≥ (zoneBottom − ATR × tolerance)
AND VWAP ≤ (zoneTop + ATR × tolerance)
When true, zone receives +25 score and ⊕V tag on label.
━━━━━━━━━━━━━━━━━━━━
MULTI-TIMEFRAME ZONE OVERLAY
━━━━━━━━━━━━━━━━━━━━
Same detection logic runs on a higher timeframe via:
request.security(syminfo.tickerid, htfRes, f_htfDetect(), lookahead=barmerge.lookahead_off)
HTF zones drawn with dashed blue borders. When LTF zone overlaps active HTF zone it receives +20 confluence bonus and ⊕H label tag. HTF zones auto-mitigated when price closes through them.
━━━━━━━━━━━━━━━━━━━━
LIQUIDITY SWEEP DETECTION
━━━━━━━━━━━━━━━━━━━━
A liquidity sweep is defined as:
For demand zones (⚡BUY):
- bar[1] low < zone bottom — wick pierced below
- bar[1] close > zone bottom — body reclaimed inside zone
- Sweep depth = (zoneBottom − low[1]) / close ≥ minimum threshold
- Current bar confirms bullish (close > open)
For supply zones (⚡SELL): inverse conditions apply.
This represents institutional stop hunting — retail stops below a structural low are triggered, price immediately reverses. These are marked as ⚡BUY / ⚡SELL, visually distinct from regular signals.
━━━━━━━━━━━━━━━━━━━━
SIGNAL LOGIC
━━━━━━━━━━━━━━━━━━━━
Regular BUY signal fires when all confirmed on closed bar:
- Price taps active demand zone (low ≤ zone top)
- Close back above zone top — bullish body
- Lower wick ≥ 50% of candle range — rejection confirmation
- Trend filter: close > EMA(50) — directional bias
- Zone grade meets minimum requirement
- Zone not yet used (one-signal-per-zone mode)
- Cooldown bars passed since last signal
Inverse for SELL at supply zones.
━━━━━━━━━━━━━━━━━━━━
ZONE MITIGATION
━━━━━━━━━━━━━━━━━━━━
Two modes:
- Body Close: zone removed when candle body closes through zone boundary
- Wick Touch: zone removed when any wick touches zone boundary
Mitigated zones are deleted from chart automatically. All related labels and badges deleted simultaneously via parallel array management.
━━━━━━━━━━━━━━━━━━━━
LIVE BACKTEST PANEL
━━━━━━━━━━━━━━━━━━━━
Every fired signal is logged with: entry price, ATR at entry, direction, bar index. On subsequent bars the script evaluates:
- Win: price reaches entry ± (ATR × targetMultiplier) in signal direction
- Loss: price reaches entry ∓ (ATR × stopMultiplier) against signal direction
First level hit determines outcome. Panel displays:
- Total signals tracked (configurable max, default 50)
- Wins / Losses / Open
- Win rate %
- Average R-multiple = (wins × targetMult − losses × stopMult) / closed signals
This is a logic-level simulation using OHLC data. Not slippage or fee adjusted.
━━━━━━━━━━━━━━━━━━━━
WHAT IS ORIGINAL
━━━━━━━━━━━━━━━━━━━━
- Quantitative zone grading (0–100 score → A+/A/B/C) based on four measurable confluences
- Liquidity sweep detection as a separate premium signal class
- VWAP proximity as a scored confluence factor (not just an overlay)
- HTF zone overlap as a scored confluence factor
- Live backtest panel tracking actual signal outcomes with R-multiple
- Adaptive zone extension — boxes track current bar instead of extending infinitely
- All filters stackable independently: grade, trend, wick size, cooldown, session, freshness
━━━━━━━━━━━━━━━━━━━━
HOW TO USE
━━━━━━━━━━━━━━━━━━━━
- Green boxes = demand zones | Red boxes = supply zones
- Dashed blue boxes = higher timeframe zones
- Grade badge inside each zone: A+ (yellow) / A (orange) / B (gray) / C (faded)
- ⊕V = VWAP confluence | ⊕H = HTF confluence
- Triangle up = BUY signal | Triangle down = SELL signal
- ⚡BUY / ⚡SELL = liquidity sweep signals (highest probability)
Recommended workflow:
1. Identify A or A+ graded zones with ⊕V or ⊕H tags
2. Wait for price to return to zone
3. Enter on BUY/SELL signal — wick rejection + bullish/bearish close
4. Prioritize ⚡ sweep signals when available
5. Monitor backtest panel to confirm positive expectancy on your asset
━━━━━━━━━━━━━━━━━━━━
RECOMMENDED SETTINGS
━━━━━━━━━━━━━━━━━━━━
- Forex / Gold (XAUUSD): Volume confirmation OFF
- Stocks / Crypto / Futures: Volume confirmation ON
- Scalping: 5m–15m chart, HTF = 1H
- Intraday: 15m–1H chart, HTF = 4H
- Conservative: Min Grade = A, Cooldown = 10
- Aggressive: Min Grade = B, Cooldown = 5
━━━━━━━━━━━━━━━━━━━━
No repainting. No lookahead bias. All signals fire on barstate.isconfirmed only.
Detection uses bar[1] and bar[2] historical references exclusively.
WHY THESE COMPONENTS WORK TOGETHER
Supply and demand zones identify WHERE price is likely to react. VWAP identifies WHERE fair value sits. Neither alone confirms institutional intent. When a zone aligns with VWAP and a higher-timeframe zone simultaneously, the probability of a genuine institutional reaction increases measurably. The liquidity sweep signal adds a third layer — detecting when stops are hunted before reversal. These three components cannot produce the same edge independently; the confluence scoring model is what ties them into one system.
by ApexFlow
━━━━━━━━━━━━━━━━━━━━
INSPIRATION & CREDIT
━━━━━━━━━━━━━━━━━━━━
Credit: Zone base detection concept inspired by "Market Structure Break & Orderblock" by EmreKb (TradingView open-source). All code has been rewritten with significant original additions: quantitative grading system (A+/A/B/C), VWAP confluence scoring, liquidity sweep detection, multi-timeframe overlay, and live backtest panel.
━━━━━━━━━━━━━━━━━━━━
WHAT THIS INDICATOR DOES
━━━━━━━━━━━━━━━━━━━━
Detects institutional supply and demand zones using a three-layer confluence model:
1. Zone formation: explosive impulsive move + consolidation base
2. Zone scoring: quantitative grade based on move strength, volume, VWAP proximity, HTF overlap
3. Signal generation: price returns to zone with rejection confirmation + sweep detection
The combination of these three layers separates this from standard S&D indicators that draw zones without qualification.
━━━━━━━━━━━━━━━━━━━━
ZONE DETECTION METHODOLOGY
━━━━━━━━━━━━━━━━━━━━
A zone forms when a confirmed bar (barstate.isconfirmed) meets all of:
- Bar range > ATR(14) × Move Multiplier — confirms volatility expansion
- Candle body > 55% of total range — filters wicky, indecisive bars
- Optional: Volume > SMA(20) × multiplier — confirms participation
ATR uses ta.atr(14). Body percentage = |close − open| / (high − low).
The base of the zone is built from preceding candle(s) where:
- |close − open| < ATR × 0.5 (small-bodied consolidation)
- Bar is not itself explosive
Base high and low define the zone boundaries:
- Supply zone: base candle(s) before bearish explosive move
→ Top = base high, Bottom = min(base low, explosive open)
- Demand zone: base candle(s) before bullish explosive move
→ Top = max(base high, explosive open), Bottom = base low
All detection references bar[1] and bar[2] on confirmed bars only. No repainting, no lookahead.
━━━━━━━━━━━━━━━━━━━━
ZONE GRADING SYSTEM (A+ / A / B / C)
━━━━━━━━━━━━━━━━━━━━
Each zone receives a score from 0–100 at creation using four measurable factors:
Move strength (max 30 pts):
- score += min((range[1] / ATR[1]) × 18, 30)
Volume strength (max 20 pts):
- score += min((volume[1] / volAvg[1]) × 13, 20)
- If volume confirmation disabled: default 10 pts
VWAP confluence (25 pts):
- +25 if session VWAP falls within zone ± (ATR × tolerance)
- Uses ta.vwap (session-anchored)
HTF zone overlap (20 pts):
- +20 if zone price range overlaps a detected higher-timeframe zone
- HTF data pulled via request.security() with lookahead=barmerge.lookahead_off
Freshness bonus (5 pts):
- +5 at creation
Grade thresholds:
- A+ ≥ 80 | A ≥ 65 | B ≥ 50 | C < 50
Grade displayed as badge inside each zone. Signals filterable by minimum grade.
━━━━━━━━━━━━━━━━━━━━
VWAP CONFLUENCE
━━━━━━━━━━━━━━━━━━━━
Session VWAP (ta.vwap) compared to each new zone at creation:
vwapInZone = VWAP ≥ (zoneBottom − ATR × tolerance)
AND VWAP ≤ (zoneTop + ATR × tolerance)
When true, zone receives +25 score and ⊕V tag on label.
━━━━━━━━━━━━━━━━━━━━
MULTI-TIMEFRAME ZONE OVERLAY
━━━━━━━━━━━━━━━━━━━━
Same detection logic runs on a higher timeframe via:
request.security(syminfo.tickerid, htfRes, f_htfDetect(), lookahead=barmerge.lookahead_off)
HTF zones drawn with dashed blue borders. When LTF zone overlaps active HTF zone it receives +20 confluence bonus and ⊕H label tag. HTF zones auto-mitigated when price closes through them.
━━━━━━━━━━━━━━━━━━━━
LIQUIDITY SWEEP DETECTION
━━━━━━━━━━━━━━━━━━━━
A liquidity sweep is defined as:
For demand zones (⚡BUY):
- bar[1] low < zone bottom — wick pierced below
- bar[1] close > zone bottom — body reclaimed inside zone
- Sweep depth = (zoneBottom − low[1]) / close ≥ minimum threshold
- Current bar confirms bullish (close > open)
For supply zones (⚡SELL): inverse conditions apply.
This represents institutional stop hunting — retail stops below a structural low are triggered, price immediately reverses. These are marked as ⚡BUY / ⚡SELL, visually distinct from regular signals.
━━━━━━━━━━━━━━━━━━━━
SIGNAL LOGIC
━━━━━━━━━━━━━━━━━━━━
Regular BUY signal fires when all confirmed on closed bar:
- Price taps active demand zone (low ≤ zone top)
- Close back above zone top — bullish body
- Lower wick ≥ 50% of candle range — rejection confirmation
- Trend filter: close > EMA(50) — directional bias
- Zone grade meets minimum requirement
- Zone not yet used (one-signal-per-zone mode)
- Cooldown bars passed since last signal
Inverse for SELL at supply zones.
━━━━━━━━━━━━━━━━━━━━
ZONE MITIGATION
━━━━━━━━━━━━━━━━━━━━
Two modes:
- Body Close: zone removed when candle body closes through zone boundary
- Wick Touch: zone removed when any wick touches zone boundary
Mitigated zones are deleted from chart automatically. All related labels and badges deleted simultaneously via parallel array management.
━━━━━━━━━━━━━━━━━━━━
LIVE BACKTEST PANEL
━━━━━━━━━━━━━━━━━━━━
Every fired signal is logged with: entry price, ATR at entry, direction, bar index. On subsequent bars the script evaluates:
- Win: price reaches entry ± (ATR × targetMultiplier) in signal direction
- Loss: price reaches entry ∓ (ATR × stopMultiplier) against signal direction
First level hit determines outcome. Panel displays:
- Total signals tracked (configurable max, default 50)
- Wins / Losses / Open
- Win rate %
- Average R-multiple = (wins × targetMult − losses × stopMult) / closed signals
This is a logic-level simulation using OHLC data. Not slippage or fee adjusted.
━━━━━━━━━━━━━━━━━━━━
WHAT IS ORIGINAL
━━━━━━━━━━━━━━━━━━━━
- Quantitative zone grading (0–100 score → A+/A/B/C) based on four measurable confluences
- Liquidity sweep detection as a separate premium signal class
- VWAP proximity as a scored confluence factor (not just an overlay)
- HTF zone overlap as a scored confluence factor
- Live backtest panel tracking actual signal outcomes with R-multiple
- Adaptive zone extension — boxes track current bar instead of extending infinitely
- All filters stackable independently: grade, trend, wick size, cooldown, session, freshness
━━━━━━━━━━━━━━━━━━━━
HOW TO USE
━━━━━━━━━━━━━━━━━━━━
- Green boxes = demand zones | Red boxes = supply zones
- Dashed blue boxes = higher timeframe zones
- Grade badge inside each zone: A+ (yellow) / A (orange) / B (gray) / C (faded)
- ⊕V = VWAP confluence | ⊕H = HTF confluence
- Triangle up = BUY signal | Triangle down = SELL signal
- ⚡BUY / ⚡SELL = liquidity sweep signals (highest probability)
Recommended workflow:
1. Identify A or A+ graded zones with ⊕V or ⊕H tags
2. Wait for price to return to zone
3. Enter on BUY/SELL signal — wick rejection + bullish/bearish close
4. Prioritize ⚡ sweep signals when available
5. Monitor backtest panel to confirm positive expectancy on your asset
━━━━━━━━━━━━━━━━━━━━
RECOMMENDED SETTINGS
━━━━━━━━━━━━━━━━━━━━
- Forex / Gold (XAUUSD): Volume confirmation OFF
- Stocks / Crypto / Futures: Volume confirmation ON
- Scalping: 5m–15m chart, HTF = 1H
- Intraday: 15m–1H chart, HTF = 4H
- Conservative: Min Grade = A, Cooldown = 10
- Aggressive: Min Grade = B, Cooldown = 5
━━━━━━━━━━━━━━━━━━━━
No repainting. No lookahead bias. All signals fire on barstate.isconfirmed only.
Detection uses bar[1] and bar[2] historical references exclusively.
WHY THESE COMPONENTS WORK TOGETHER
Supply and demand zones identify WHERE price is likely to react. VWAP identifies WHERE fair value sits. Neither alone confirms institutional intent. When a zone aligns with VWAP and a higher-timeframe zone simultaneously, the probability of a genuine institutional reaction increases measurably. The liquidity sweep signal adds a third layer — detecting when stops are hunted before reversal. These three components cannot produce the same edge independently; the confluence scoring model is what ties them into one system.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.