OPEN-SOURCE SCRIPT
Supply & Demand Zones

**Overview**
This indicator builds Supply & Demand Zones automatically based on the pivot-detection logic from LuxAlgo's "Support and Resistance Levels with Breaks". Instead of plotting individual support/resistance lines, it groups them into meaningful zones that reflect real areas of buying and selling pressure.
**How It Works**
The indicator identifies Pivot Highs and Pivot Lows within the most recent 500 bars. It then pairs them to form zones:
- **Supply Zones (Red)**: Resistance levels sorted from high to low, paired consecutively (1st+2nd, 3rd+4th…)
- **Demand Zones (Blue)**: Support levels sorted from low to high, paired consecutively (1st+2nd, 3rd+4th…)
**Zone Invalidation**
A zone is automatically removed when price breaches it:
- Supply Zone: invalidated when any bar's **high** exceeds the upper boundary
- Demand Zone: invalidated when any bar's **low** breaks below the lower boundary
Only **active, untested zones** are displayed on the chart.
**Settings**
| Parameter | Description |
|---|---|
| Left Bars | Bars to the left for pivot confirmation |
| Right Bars | Bars to the right for pivot confirmation |
| Max Pivots | Maximum number of recent pivots to retain |
| Extend Right | How many bars to extend zones to the right |
**Credits**
Pivot logic adapted from © LuxAlgo — Support and Resistance Levels with Breaks (CC BY-NC-SA 4.0)
---
**概述**
本指标基于 LuxAlgo「Support and Resistance Levels with Breaks」的 Pivot 计算逻辑进行改编,将原本的支撑/阻力线升级为**供需区(矩形区间)**,更直观地标注出市场中真实的买卖压力区域。
**计算逻辑**
指标在最近500根K线范围内,识别所有 Pivot High(阻力位)和 Pivot Low(支撑位),然后两两配对生成区间:
- **供给区(红色)**:阻力线从高到低排序,第1+2条组成区间一,第3+4条组成区间二,以此类推
- **需求区(蓝色)**:支撑线从低到高排序,第1+2条组成区间一,第3+4条组成区间二,以此类推
**区间失效规则**
区间被价格测试破坏后,自动从图表中移除,不再显示:
- 供给区失效:任意K线**最高价 > 区间上边界**
- 需求区失效:任意K线**最低价 < 区间下边界**
图表上只显示**当前仍然有效、未被突破的区间**。
**参数说明**
| 参数 | 说明 |
|---|---|
| Left Bars | Pivot 确认所需左侧K线数 |
| Right Bars | Pivot 确认所需右侧K线数 |
| Max Pivots | 保留的最近 Pivot 数量上限 |
| 向右延伸 | 区间向右延伸的K线根数 |
**致谢**
Pivot 计算逻辑改编自 © LuxAlgo — Support and Resistance Levels with Breaks,遵循 CC BY-NC-SA 4.0 协议。
This indicator builds Supply & Demand Zones automatically based on the pivot-detection logic from LuxAlgo's "Support and Resistance Levels with Breaks". Instead of plotting individual support/resistance lines, it groups them into meaningful zones that reflect real areas of buying and selling pressure.
**How It Works**
The indicator identifies Pivot Highs and Pivot Lows within the most recent 500 bars. It then pairs them to form zones:
- **Supply Zones (Red)**: Resistance levels sorted from high to low, paired consecutively (1st+2nd, 3rd+4th…)
- **Demand Zones (Blue)**: Support levels sorted from low to high, paired consecutively (1st+2nd, 3rd+4th…)
**Zone Invalidation**
A zone is automatically removed when price breaches it:
- Supply Zone: invalidated when any bar's **high** exceeds the upper boundary
- Demand Zone: invalidated when any bar's **low** breaks below the lower boundary
Only **active, untested zones** are displayed on the chart.
**Settings**
| Parameter | Description |
|---|---|
| Left Bars | Bars to the left for pivot confirmation |
| Right Bars | Bars to the right for pivot confirmation |
| Max Pivots | Maximum number of recent pivots to retain |
| Extend Right | How many bars to extend zones to the right |
**Credits**
Pivot logic adapted from © LuxAlgo — Support and Resistance Levels with Breaks (CC BY-NC-SA 4.0)
---
**概述**
本指标基于 LuxAlgo「Support and Resistance Levels with Breaks」的 Pivot 计算逻辑进行改编,将原本的支撑/阻力线升级为**供需区(矩形区间)**,更直观地标注出市场中真实的买卖压力区域。
**计算逻辑**
指标在最近500根K线范围内,识别所有 Pivot High(阻力位)和 Pivot Low(支撑位),然后两两配对生成区间:
- **供给区(红色)**:阻力线从高到低排序,第1+2条组成区间一,第3+4条组成区间二,以此类推
- **需求区(蓝色)**:支撑线从低到高排序,第1+2条组成区间一,第3+4条组成区间二,以此类推
**区间失效规则**
区间被价格测试破坏后,自动从图表中移除,不再显示:
- 供给区失效:任意K线**最高价 > 区间上边界**
- 需求区失效:任意K线**最低价 < 区间下边界**
图表上只显示**当前仍然有效、未被突破的区间**。
**参数说明**
| 参数 | 说明 |
|---|---|
| Left Bars | Pivot 确认所需左侧K线数 |
| Right Bars | Pivot 确认所需右侧K线数 |
| Max Pivots | 保留的最近 Pivot 数量上限 |
| 向右延伸 | 区间向右延伸的K线根数 |
**致谢**
Pivot 计算逻辑改编自 © LuxAlgo — Support and Resistance Levels with Breaks,遵循 CC BY-NC-SA 4.0 协议。
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.