OPEN-SOURCE SCRIPT
Neighboring Price Dispersion [LuxAlgo]

The Neighboring Price Dispersion indicator calculates the standard deviation of historical prices within a specific price-based neighborhood of the current market level, providing a unique perspective on local price density and volatility within a long-term distribution.
🔶 USAGE
The indicator is displayed in a separate pane and represents the volatility of prices immediately surrounding the current market price based on a historical buffer. Unlike standard volatility indicators that measure price change over time, this tool measures the spread of prices across "price space."
Users can use this tool to identify "Price Discovery" zones or areas where the current price is trading in historical voids. When the indicator line disappears and the background is highlighted, it indicates that the current price has few or no "neighbors" within the historical distribution, suggesting the market is exploring new price levels.
🔹 Interpreting Dispersion
🔶 DETAILS
The script maintains a historical buffer of OHLC values (up to 20,000 data points) which are stored in a sorted array. This allows the indicator to construct a "Global Price Distribution" that evolves with every new bar.
Instead of calculating volatility over a lookback period of bars, the script finds the position of the current closing price within the sorted distribution and calculates the standard deviation of the K nearest neighbors.
If the current price is trading in a range it has rarely or never visited within the defined buffer, the indicator will stop plotting. This visual cue signifies that the asset is currently in a state of "discovery," as there is insufficient historical data in that specific price range to determine a local dispersion.
🔶 SETTINGS
🔶 USAGE
The indicator is displayed in a separate pane and represents the volatility of prices immediately surrounding the current market price based on a historical buffer. Unlike standard volatility indicators that measure price change over time, this tool measures the spread of prices across "price space."
Users can use this tool to identify "Price Discovery" zones or areas where the current price is trading in historical voids. When the indicator line disappears and the background is highlighted, it indicates that the current price has few or no "neighbors" within the historical distribution, suggesting the market is exploring new price levels.
🔹 Interpreting Dispersion
- High Dispersion: Indicates that historical price points near the current level are widely spread out. This often suggests a lack of historical agreement on value at that level or a "thin" market area.
- Low Dispersion: Suggests high price density, where many historical data points (OHLC values) are clustered together. These areas often act as "fair value" zones or high-liquidity regions where the market has spent significant time.
- Background Highlights: When the background is colored, it signifies a "Discovery" phase. This occurs when the current price is at an extreme (all-time high/low within the buffer) or in a gap where there aren't enough historical neighbors to calculate a valid dispersion.
- Signal Components: The indicator includes an orange Signal MA to help identify trends in dispersion and a white Cumulative Mean line to represent the long-term average dispersion of the current session.
🔶 DETAILS
The script maintains a historical buffer of OHLC values (up to 20,000 data points) which are stored in a sorted array. This allows the indicator to construct a "Global Price Distribution" that evolves with every new bar.
Instead of calculating volatility over a lookback period of bars, the script finds the position of the current closing price within the sorted distribution and calculates the standard deviation of the K nearest neighbors.
If the current price is trading in a range it has rarely or never visited within the defined buffer, the indicator will stop plotting. This visual cue signifies that the asset is currently in a state of "discovery," as there is insufficient historical data in that specific price range to determine a local dispersion.
🔶 SETTINGS
- Historical Buffer (Bars): The number of historical bars used to build the price distribution. A higher value provides a longer-term memory of price levels.
- Neighboring Range (K): The number of neighboring price points to include in the standard deviation calculation. Smaller values respond more quickly to local gaps, while larger values provide a broader view of density.
- Smoothing: Applies a Simple Moving Average (SMA) to the dispersion calculation to filter out noise and produce smoother visual transitions.
- MA Length: Sets the period for the signal moving average (orange line). This helps smooth the dispersion data to identify broader shifts in price density.
- CMean Multiplier: A multiplier applied to the cumulative mean of the dispersion. This adjusts the level of the white baseline relative to the current dispersion values.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
All content & scripts provided by LuxAlgo are for educational purposes only and are not financial advice.
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
All content & scripts provided by LuxAlgo are for educational purposes only and are not financial advice.
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。