OPEN-SOURCE SCRIPT
Zaktualizowano Directional Purity

Directional Purity [Community Edition]
Rather than a simple standalone strategy, Directional Purity is a professional trend-filtering and directional stability engine designed to supercharge any existing trading strategy. It eliminates the fatal flaw of traditional indicators like ADX—which measure trend strength with significant lag—by equipping your strategy with a zero-lag, mathematically precise gauge of directional purity.
Traditionally, ADX relies on double-smoothed EMAs of directional movements, causing delayed responses to trend breakouts and exhaustion. Directional Purity resolves this by using the mathematical equivalence of Chande's CMO and Kaufman's Efficiency Ratio (ER) as a volatility index to dynamically adapt a 13-period VIDYA (Variable Index Dynamic Average) base.
By utilizing a telescoping sum optimization, this script is fully vectorized (loop-free), ensuring extremely fast execution on any time frame.
Features:
- Live Dashboard: Shows real-time market state (Trending Bullish, Trending Bearish, Ranging) and Trend Purity %.
- Visual Fills: Highlights ranging zones in gray to prevent overtrading.
- Built-in Alerts: Triggers for trend breakouts, entering ranges, and direction shifts.
```
Rather than a simple standalone strategy, Directional Purity is a professional trend-filtering and directional stability engine designed to supercharge any existing trading strategy. It eliminates the fatal flaw of traditional indicators like ADX—which measure trend strength with significant lag—by equipping your strategy with a zero-lag, mathematically precise gauge of directional purity.
Traditionally, ADX relies on double-smoothed EMAs of directional movements, causing delayed responses to trend breakouts and exhaustion. Directional Purity resolves this by using the mathematical equivalence of Chande's CMO and Kaufman's Efficiency Ratio (ER) as a volatility index to dynamically adapt a 13-period VIDYA (Variable Index Dynamic Average) base.
By utilizing a telescoping sum optimization, this script is fully vectorized (loop-free), ensuring extremely fast execution on any time frame.
Features:
- Live Dashboard: Shows real-time market state (Trending Bullish, Trending Bearish, Ranging) and Trend Purity %.
- Visual Fills: Highlights ranging zones in gray to prevent overtrading.
- Built-in Alerts: Triggers for trend breakouts, entering ranges, and direction shifts.
```
Informacje o Wersji
Version 2.0 Release Notes:1. Pine Script v6 Upgrade: The codebase has been fully upgraded to the latest version 6 standard.
2. Vectorized Performance Optimization: Removed all nested loop structures in the volatility calculation. Utilizing a telescoping sum mathematical proof, the core engine has been fully vectorized using `math.sum()` for instantaneous chart rendering.
3. Real-Time Info Dashboard: Added a clean table overlay displaying current market state (Trending Bullish, Trending Bearish, Ranging) and the exact purity strength percentage.
4. Organized UI: Grouped all parameters with descriptive tooltips for a premium user experience.
5. Improved Alert System: Upgraded and modernized alert conditions for trend breakouts, ranges, and direction shifts.
Informacje o Wersji
Changes Made1. Dynamic Threshold Line & Numeric Label
Changed the static threshold representation from hline() to a dynamic plot() function (plot(threshold)). This ensures that when a user updates the Trend Threshold in the indicator settings dialog, the line moves immediately to the new value on the chart.
Added a label.new() function that dynamically creates and positions a text label displaying Threshold: [Value] (e.g. Threshold: 0.25) on the right margin of the chart next to the threshold line. This provides immediate numerical feedback directly in the indicator pane.
2. Real-Time Price Tick Normalization
Added a new input toggle:
"Calculate Only on Bar Close" (calc_on_close).
Introduced a source variable src that handles the normalization logic:
pinescript
src = calc_on_close and not barstate.isconfirmed ? close[1] : close
Replaced occurrences of close with src in all calculation engines and state logic (such as f_directional_purity, recursive vidya calculations, and trend state checks).
When the setting is checked, the indicator stays completely stable on the real-time bar by using the previous bar's closed price, preventing the purity line, ranging background highlights, dashboard stats, and alerts from jittering on every incoming price tick.
Informacje o Wersji
- **Purity Smoothing (EMA, default: 3):** To filter out short-term fluctuations and prevent visual zigzags, the raw purity is smoothed using an EMA before plotting and calculation.- **Hysteresis Buffer (default: 0.05):** A dual-threshold filter. The trend only returns to a ranging state if purity drops below `threshold - hysteresis_buffer` (e.g., $0.20$ if threshold is $0.25$). This prevents whipsawing in choppy ranges.
Informacje o Wersji
Release Update: Performance Optimization & Logical RefinementsThis update focuses on engine optimization to significantly reduce memory overhead, eliminate visual flickering, and polish alert logic:
Memory & Rendering Optimization (Table & Label):
Info Dashboard Table: The
info_table
is now initialized once using var instead of being destroyed and recreated on every price tick. It now only updates cell values on the last bar, significantly lowering browser CPU overhead.
Threshold Label: Replaced the delete-and-recreate loop of the
thresh_label
in the sub-pane with efficient label.set_* setter functions, completely eliminating visual flickering on active price feeds.
Warm-up / NaN Formatting Polish:
Handled startup values when the CMO/EMA periods are not yet fully primed. The dashboard now cleanly displays "N/A" instead of "NaN%" during the warm-up phase.
Alert Logic Refinement (Trend Direction Change):
Added and not ranging[1] to the Trend Direction Change alert condition. This prevents the alert from double-triggering on the exact breakout bar of a new trend, making sure it only fires when a mature trend reverses direction.
Pine Script v6 Strict Compliance:
Fully refactored under modern Pine Script v6 guidelines, utilizing robust type handling and safe object updates.
Informacje o Wersji
Release Update: Performance Optimizations, Unit & Alert SynchronizationThis update resolves unit display discrepancies, standardizes alert placeholders, and optimizes chart rendering for high performance:
1. Rendering & Memory Optimizations:
- The threshold label now uses label.set_* methods to update in place instead of being destroyed and recreated on every price tick, eliminating flickering.
- The info dashboard table is now initialized once using "var" to prevent browser CPU overhead during active market ticks.
2. Unit & Dashboard Alignment:
- Aligned the dashboard purity value to match the 0.00 - 1.00 scale of the oscillator and threshold labels (e.g., showing "0.42" instead of percentage). Displays "N/A" during the startup warm-up phase.
3. Alert Template Standardization:
- Standardized the alert messages with dynamic ticker and interval placeholders ({{ticker}} {{interval}}) across all configurations.
- Refined the Trend Direction Change alert logic to ignore the initial breakout bar, preventing double-alerts on trend starts.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.