OPEN-SOURCE SCRIPT
Auto Supply & Demand Zones [Proozac]

# Auto Supply & Demand Zones
**Pine Script v6 — Overlay Indicator**
---
## What It Does
Automatically identifies and draws **Supply** and **Demand** zones using a consolidation-then-impulse approach. Instead of drawing arbitrary rectangles around wicks or candles, this indicator marks the precise origin of impulsive moves — the base where institutions accumulated or distributed positions before the explosive move began.
Zones update dynamically: they extend to the current bar as long as they are active, fade when price re-enters them (tested), and can be removed automatically when fully mitigated.
---
## Core Concept
Supply and Demand zones are based on the observation that before a strong directional move, price always consolidates in a narrow range. This consolidation is where orders were placed. When price eventually returns to that origin area, those resting orders become relevant again.
```
DEMAND ZONE (base before impulsive UP move)
────────────────────────────────────
[consolidation base] ← zone drawn here
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ← impulsive bullish candle
SUPPLY ZONE (base before impulsive DOWN move)
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ← impulsive bearish candle
[consolidation base] ← zone drawn here
────────────────────────────────────
```
---
## Detection Logic
### Step 1 — Identify the Base (Consolidation)
A "base" is a sequence of `Consolidation Bars` consecutive candles where every candle body is **smaller than the ATR**:
```
For each candle in the base window:
body = |close - open|
if body > ATR → not a base
```
This filters out directional candles and keeps only tight, sideways price action — the footprint of institutional accumulation/distribution.
### Step 2 — Detect the Impulse
An impulse candle is a strong directional candle **immediately after** the base:
```
Bullish impulse: base confirmed AND close > open AND (close - open) > ATR × Impulse Strength
Bearish impulse: base confirmed AND close < open AND (open - close) > ATR × Impulse Strength
```
The `Impulse Strength` multiplier controls how strong the breakout candle must be relative to ATR. At 1.5× ATR, only genuinely strong moves qualify.
### Step 3 — Draw the Zone
The zone is drawn over the **range of the consolidation base** (highest high to lowest low across all base candles):
```
Zone top = max(high) across base candles
Zone bottom = min(low) across base candles
```
- Bullish impulse → **Demand zone** (green box)
- Bearish impulse → **Supply zone** (red box)
---
## Zone Lifecycle
| State | Visual | Condition |
|-------|--------|-----------|
| **Active** | Full color, solid border | Price has not returned to the zone |
| **Tested** | Price is currently inside the zone | Background flashes, border highlights |
| **Mitigated** | Faded to high transparency | Price closed through the zone's far edge |
| **Deleted** | Removed from chart | Only if "Keep Tested Zones" is off |
Zone mitigation rules:
- Demand zone → mitigated when `low < zone bottom` (price broke below it)
- Supply zone → mitigated when `high > zone top` (price broke above it)
---
## Inputs
| Input | Default | Description |
|-------|---------|-------------|
| **Consolidation Bars** | 3 | Number of tight candles required to form a base. More bars = stricter, rarer zones |
| **Impulse Strength (×ATR)** | 1.5 | How strong the breakout candle must be vs ATR. Higher = stronger impulses only |
| **ATR Length** | 14 | Period for the ATR used in base and impulse detection |
| **Max Active Zones** | 10 | Maximum number of zones kept per side (oldest removed first) |
| **Demand Zone Color** | Teal/green | Fill color for demand zones |
| **Supply Zone Color** | Red | Fill color for supply zones |
| **Demand/Supply Border** | Darker tint | Border color |
| **Tested Zone Transparency** | 92 | Opacity of mitigated zones (higher = more transparent) |
| **Show Zone Labels** | true | Draws "Demand" / "Supply" text inside each box |
| **Keep Tested Zones (Faded)** | true | When off, mitigated zones are deleted entirely |
---
## Visual Output
| Element | Description |
|---------|-------------|
| Green box | Active demand zone (base of a bullish impulse) |
| Red box | Active supply zone (base of a bearish impulse) |
| Faded green box | Demand zone that has been mitigated |
| Faded red box | Supply zone that has been mitigated |
| Green triangle below bar | New demand zone created this bar |
| Red triangle above bar | New supply zone created this bar |
| Green background flash | Price is currently inside a demand zone |
| Red background flash | Price is currently inside a supply zone |
---
## How to Use
**Basic trade setup:**
1. Wait for price to return to an active zone.
2. Look for a confirmation signal inside the zone — a rejection candle, a sweep of the zone's inner extreme, or a divergence from an oscillator.
3. Enter with a stop beyond the zone's outer edge.
4. Target the next supply zone (from demand) or next demand zone (from supply).
**Confluence checklist:**
- Zone is fresh (not previously tested)
- Zone aligns with a higher timeframe level
- MTF Dashboard (indicator 02) shows agreement on the entry direction
- A Liquidity Sweep (indicator 03) fired near the zone entry
**Zone freshness matters:** The first time price returns to a zone, the fill rate is significantly higher than on second or third tests. After a zone is mitigated, treat it as much weaker.
---
## Configuration Tips
| Scenario | Suggested settings |
|----------|--------------------|
| Clean, infrequent zones | Consolidation: 4–5, Impulse: 2.0× |
| More zones, active markets | Consolidation: 2, Impulse: 1.2× |
| Crypto (volatile, wide spreads) | ATR: 20, Impulse: 2.0–2.5× |
| Forex (tight spreads) | ATR: 14, Impulse: 1.5× |
| Equities / indices | ATR: 14, Impulse: 1.5–2.0× |
---
## Alerts
Two built-in `alertcondition` entries:
- `Price in Demand Zone` — fires on every bar where close is inside an active demand zone
- `Price in Supply Zone` — fires on every bar where close is inside an active supply zone
Recommended alert settings: **Once per bar close** to avoid repeated triggers within the same bar.
**Pine Script v6 — Overlay Indicator**
---
## What It Does
Automatically identifies and draws **Supply** and **Demand** zones using a consolidation-then-impulse approach. Instead of drawing arbitrary rectangles around wicks or candles, this indicator marks the precise origin of impulsive moves — the base where institutions accumulated or distributed positions before the explosive move began.
Zones update dynamically: they extend to the current bar as long as they are active, fade when price re-enters them (tested), and can be removed automatically when fully mitigated.
---
## Core Concept
Supply and Demand zones are based on the observation that before a strong directional move, price always consolidates in a narrow range. This consolidation is where orders were placed. When price eventually returns to that origin area, those resting orders become relevant again.
```
DEMAND ZONE (base before impulsive UP move)
────────────────────────────────────
[consolidation base] ← zone drawn here
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ← impulsive bullish candle
SUPPLY ZONE (base before impulsive DOWN move)
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ← impulsive bearish candle
[consolidation base] ← zone drawn here
────────────────────────────────────
```
---
## Detection Logic
### Step 1 — Identify the Base (Consolidation)
A "base" is a sequence of `Consolidation Bars` consecutive candles where every candle body is **smaller than the ATR**:
```
For each candle in the base window:
body = |close - open|
if body > ATR → not a base
```
This filters out directional candles and keeps only tight, sideways price action — the footprint of institutional accumulation/distribution.
### Step 2 — Detect the Impulse
An impulse candle is a strong directional candle **immediately after** the base:
```
Bullish impulse: base confirmed AND close > open AND (close - open) > ATR × Impulse Strength
Bearish impulse: base confirmed AND close < open AND (open - close) > ATR × Impulse Strength
```
The `Impulse Strength` multiplier controls how strong the breakout candle must be relative to ATR. At 1.5× ATR, only genuinely strong moves qualify.
### Step 3 — Draw the Zone
The zone is drawn over the **range of the consolidation base** (highest high to lowest low across all base candles):
```
Zone top = max(high) across base candles
Zone bottom = min(low) across base candles
```
- Bullish impulse → **Demand zone** (green box)
- Bearish impulse → **Supply zone** (red box)
---
## Zone Lifecycle
| State | Visual | Condition |
|-------|--------|-----------|
| **Active** | Full color, solid border | Price has not returned to the zone |
| **Tested** | Price is currently inside the zone | Background flashes, border highlights |
| **Mitigated** | Faded to high transparency | Price closed through the zone's far edge |
| **Deleted** | Removed from chart | Only if "Keep Tested Zones" is off |
Zone mitigation rules:
- Demand zone → mitigated when `low < zone bottom` (price broke below it)
- Supply zone → mitigated when `high > zone top` (price broke above it)
---
## Inputs
| Input | Default | Description |
|-------|---------|-------------|
| **Consolidation Bars** | 3 | Number of tight candles required to form a base. More bars = stricter, rarer zones |
| **Impulse Strength (×ATR)** | 1.5 | How strong the breakout candle must be vs ATR. Higher = stronger impulses only |
| **ATR Length** | 14 | Period for the ATR used in base and impulse detection |
| **Max Active Zones** | 10 | Maximum number of zones kept per side (oldest removed first) |
| **Demand Zone Color** | Teal/green | Fill color for demand zones |
| **Supply Zone Color** | Red | Fill color for supply zones |
| **Demand/Supply Border** | Darker tint | Border color |
| **Tested Zone Transparency** | 92 | Opacity of mitigated zones (higher = more transparent) |
| **Show Zone Labels** | true | Draws "Demand" / "Supply" text inside each box |
| **Keep Tested Zones (Faded)** | true | When off, mitigated zones are deleted entirely |
---
## Visual Output
| Element | Description |
|---------|-------------|
| Green box | Active demand zone (base of a bullish impulse) |
| Red box | Active supply zone (base of a bearish impulse) |
| Faded green box | Demand zone that has been mitigated |
| Faded red box | Supply zone that has been mitigated |
| Green triangle below bar | New demand zone created this bar |
| Red triangle above bar | New supply zone created this bar |
| Green background flash | Price is currently inside a demand zone |
| Red background flash | Price is currently inside a supply zone |
---
## How to Use
**Basic trade setup:**
1. Wait for price to return to an active zone.
2. Look for a confirmation signal inside the zone — a rejection candle, a sweep of the zone's inner extreme, or a divergence from an oscillator.
3. Enter with a stop beyond the zone's outer edge.
4. Target the next supply zone (from demand) or next demand zone (from supply).
**Confluence checklist:**
- Zone is fresh (not previously tested)
- Zone aligns with a higher timeframe level
- MTF Dashboard (indicator 02) shows agreement on the entry direction
- A Liquidity Sweep (indicator 03) fired near the zone entry
**Zone freshness matters:** The first time price returns to a zone, the fill rate is significantly higher than on second or third tests. After a zone is mitigated, treat it as much weaker.
---
## Configuration Tips
| Scenario | Suggested settings |
|----------|--------------------|
| Clean, infrequent zones | Consolidation: 4–5, Impulse: 2.0× |
| More zones, active markets | Consolidation: 2, Impulse: 1.2× |
| Crypto (volatile, wide spreads) | ATR: 20, Impulse: 2.0–2.5× |
| Forex (tight spreads) | ATR: 14, Impulse: 1.5× |
| Equities / indices | ATR: 14, Impulse: 1.5–2.0× |
---
## Alerts
Two built-in `alertcondition` entries:
- `Price in Demand Zone` — fires on every bar where close is inside an active demand zone
- `Price in Supply Zone` — fires on every bar where close is inside an active supply zone
Recommended alert settings: **Once per bar close** to avoid repeated triggers within the same bar.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน