OPEN-SOURCE SCRIPT
已更新 Range Detector [NJ]

✧ OVERVIEW ✧
Range Detector identifies and highlights potential ranging market structures using pivot highs and lows combined with a two-stage confirmation process.
Confirmed ranges are displayed as boxes and remain active until price closes beyond the allowed tolerance.

✧ SETTINGS ✧
Range Tolerance %
Controls how far price may close beyond the range before it is invalidated.
Range First Confirmation %
Controls the first retracement required after both range boundaries have formed.
Range Second Confirmation %
Controls the second reversal required after the first confirmation.
Bars to Confirm the Range
Controls how long the current candidate structure may remain unconfirmed before it expires.
Pivot High/Low Lookback
Controls pivot sensitivity. Lower values detect smaller and more frequent swings, while higher values focus on larger market structures.
✧ HOW IT WORKS ✧

Range Formation
The indicator uses pivot highs and lows to define potential range boundaries. Newer same-side pivots may replace earlier ones until both boundaries are established.
Two-Stage Confirmation
A range is confirmed only after two rotations.
With the default 70% / 50% settings:
High → Low: price retraces 70% toward the high, then returns to 50%.
Low → High: price retraces 70% toward the low, then returns to 50%.
Range Invalidation
The range remains active until price closes beyond a boundary by more than the selected tolerance, measured as a percentage of the range height.
Candidate Timeout
Unconfirmed candidates must complete the confirmation sequence within the selected number of bars. Otherwise, they are discarded. The timer may restart if a newer same-side pivot replaces the current candidate.
✧ VISUALIZATION ✧

Once confirmed, the range is displayed as a box between its upper and lower boundaries.
The box is drawn retrospectively from the earliest pivot used to form the range and extends forward until the range is invalidated.
Because pivot highs and lows require future bars to be confirmed, the beginning of a range can appear several bars before the indicator could have known that the pivot was valid in real time.
✧ USAGE ✧
Range Detector can be used to identify areas of:
Sideways price action
Consolidation
Mean-reversion conditions
Support and resistance
Potential breakout structures
The detected zones can provide additional market structure context for range trading, breakout analysis, or filtering trend-following setups.
As with any technical indicator, it is best used alongside other forms of analysis rather than as a standalone entry or exit signal.
Range Detector identifies and highlights potential ranging market structures using pivot highs and lows combined with a two-stage confirmation process.
Confirmed ranges are displayed as boxes and remain active until price closes beyond the allowed tolerance.
✧ SETTINGS ✧
Range Tolerance %
Controls how far price may close beyond the range before it is invalidated.
Range First Confirmation %
Controls the first retracement required after both range boundaries have formed.
Range Second Confirmation %
Controls the second reversal required after the first confirmation.
Bars to Confirm the Range
Controls how long the current candidate structure may remain unconfirmed before it expires.
Pivot High/Low Lookback
Controls pivot sensitivity. Lower values detect smaller and more frequent swings, while higher values focus on larger market structures.
✧ HOW IT WORKS ✧
Range Formation
The indicator uses pivot highs and lows to define potential range boundaries. Newer same-side pivots may replace earlier ones until both boundaries are established.
Two-Stage Confirmation
A range is confirmed only after two rotations.
With the default 70% / 50% settings:
High → Low: price retraces 70% toward the high, then returns to 50%.
Low → High: price retraces 70% toward the low, then returns to 50%.
Range Invalidation
The range remains active until price closes beyond a boundary by more than the selected tolerance, measured as a percentage of the range height.
Candidate Timeout
Unconfirmed candidates must complete the confirmation sequence within the selected number of bars. Otherwise, they are discarded. The timer may restart if a newer same-side pivot replaces the current candidate.
✧ VISUALIZATION ✧
Once confirmed, the range is displayed as a box between its upper and lower boundaries.
The box is drawn retrospectively from the earliest pivot used to form the range and extends forward until the range is invalidated.
Because pivot highs and lows require future bars to be confirmed, the beginning of a range can appear several bars before the indicator could have known that the pivot was valid in real time.
✧ USAGE ✧
Range Detector can be used to identify areas of:
Sideways price action
Consolidation
Mean-reversion conditions
Support and resistance
Potential breakout structures
The detected zones can provide additional market structure context for range trading, breakout analysis, or filtering trend-following setups.
As with any technical indicator, it is best used alongside other forms of analysis rather than as a standalone entry or exit signal.
版本注释
Short title correction.开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。