OPEN-SOURCE SCRIPT

Support & Resistance KDE

1 669
Support & Resistance KDE (Kernel Density Estimation)

▶️Overview
This indicator identifies high-significance support and resistance (S/R) levels using Kernel Density Estimation (KDE), a sophisticated statistical method for finding price clusters.
By employing a linear kernel approach where the width is determined by the candlestick range, this tool provides a more robust estimation of S/R levels compared to simply marking discrete pivot points. It visualizes statistically significant "price walls" that represent real supply and demand zones by accounting for the price action's volatility at each historical turning point.

▶️Key Features
Statistical S/R Identification:
Uses Pivot Highs and Lows as sample data for KDE to automatically extract price levels with high historical significance.
KDE Distribution Profile:
Displays a density profile on the right side of the chart, allowing you to instantly see where the strongest price clusters are located.
Dynamic Zone Display:
Levels are displayed as "Zones" rather than thin lines, based on ATR. This helps account for market noise and provides a more realistic view of price reaction areas.
Peak Filtering:
Identifies local maxima in density and uses an ATR-based minimum distance filter to merge overlapping levels and keep the chart clean.

▶️How It Works (Logic)
The script processes data through the following steps to ensure a robust statistical analysis:

Data Collection:
Extracts all Pivot Highs and Lows within the defined Lookback Period, alongside the price range (High - Low) of the candle where the pivot occurred.
Density Calculation (Linear Kernel):
Instead of treating each pivot as a single, infinitesimal price point, the script applies a Linear (Triangular) Kernel to each pivot. The width of this kernel is defined by the candle's range at that specific time.
Mechanism:
Each pivot contributes its "weight" to a price range rather than a single value. This accounts for the volatility and uncertainty present at the moment the pivot was formed, leading to a much more reliable estimation of where "true" support or resistance lies compared to raw price data.
Peak Detection:
Scans the entire price range within the lookback period to find local maxima (peaks) in the cumulative density distribution.
Ranking and Filtering:
Ranks these peaks by density and filters them based on the user-defined "Min Distance (ATR Multiplier)" to display only the top N most significant levels.

▶️Inputs
--- Calculation Settings ---
Lookback Period: The number of bars to analyze.
Pivot Left/Right Strength: The period used to detect pivot points. Increasing these values will capture more macro-level structures.
Number of Top Levels: The maximum number of S/R levels to display.
Min Distance Between Levels: Minimum vertical distance between levels (ATR multiplier) to prevent clutter.
KDE Resolution: The granularity of the price scan for density calculation.

--- Display Settings ---
Show KDE Distribution: Toggles the visibility of the density profile on the right.
Zone Display Width: The vertical thickness of the S/R zones (ATR multiplier).

▶️Trading Use Cases
Take Profit / Stop Loss Targets: Use Level 1 (the highest density peak) as a high-probability target for exits.
Breakout Confirmation: Watch for strong candle closes outside of high-density zones as a signal of a potential trend shift.
Identifying Range Boundaries: Use the boundaries of the KDE profile to define the upper and lower limits of a consolidation phase.

Disclaimer:
This script is provided for educational and analytical purposes only and does not constitute financial advice.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.