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.
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.
All content & scripts provided by LuxAlgo are for educational purposes only and are not financial advice.
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.
All content & scripts provided by LuxAlgo are for educational purposes only and are not financial advice.
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.