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