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 协议。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。