INVITE-ONLY SCRIPT

AI-Powered Support & Resistance levels

45
AI-Powered Support & Resistance Levels

Overview
This indicator automatically identifies and plots dynamic support and resistance zones using unsupervised machine learning — specifically, a clustering algorithm applied directly to price data. Unlike traditional S/R methods that rely on fixed pivot points, manual drawing, or simple price rounding, this script uses a data-driven approach to discover where price has historically concentrated, and projects those levels as actionable zones on your chart.

How It Works — Underlying Principles

The script follows a multi-step computational process:

  1. Price Data Collection: The script collects historical low prices from bearish candles and high prices from bullish candles over a user-defined lookback period (adjustable from 50 to 5000 bars). This separation is intentional: lows from bearish candles and highs from bullish candles represent points where buying or selling pressure was most evident.

  2. Unsupervised Clustering: A machine learning clustering algorithm groups these collected prices into natural clusters — concentrations of price levels where the market has repeatedly shown interest. The algorithm iteratively assigns each price point to its nearest cluster center, then recalculates each center based on its assigned points. This process repeats until the cluster centers stabilize (converge). The result is a set of price levels that represent statistically significant areas of historical price activity.

  3. Automatic Cluster Count Optimization: Rather than requiring the user to guess how many S/R zones exist, the script includes a built-in optimization routine that tests multiple cluster counts and automatically selects the number that best balances detail against overfitting. It does this by measuring how well each cluster count explains the variance in the data, and selecting the point of diminishing returns. Users can optionally add extra zones via the "Manual Zone Adjustment" input.

  4. Volatility-Scaled Zone Width: Each zone's vertical thickness is scaled using ATR(14), so zones automatically adapt to current market volatility. Stronger clusters (containing more price points) produce wider zones, while weaker clusters produce thinner ones. This ensures zones are visually proportional to their statistical significance and remain readable across different instruments and timeframes.

  5. Role-Reversal Logic: The script applies a role-reversal principle: clustered low-price zones that sit above the current price are displayed as resistance (red), while clustered high-price zones below the current price are displayed as support (green). This reflects the well-established market concept that former support can become resistance and vice versa.


What Makes This Different From Standard S/R

Traditional support and resistance tools on TradingView typically use one of these approaches:
  • Pivot highs/lows with a fixed lookback
  • Round number levels
  • Volume profile or VWAP-based levels
  • Manually drawn horizontal lines


This script differs in several key ways:
  • Data-driven zone discovery: Zones are not placed at arbitrary pivot points or round numbers. They emerge from the statistical structure of the price data itself through iterative clustering.
  • Automatic adaptation: The number of zones, their placement, and their width all adjust automatically based on the data — no manual tuning required.
  • Volatility awareness: Zone thickness scales with ATR, so the indicator remains useful whether applied to a low-volatility forex pair or a high-volatility crypto asset.
  • Convergence-based accuracy: The clustering algorithm runs until mathematically converged, not for a fixed number of iterations, ensuring stable and reproducible results.
  • Proprietary optimization: The method used to determine the optimal number of clusters is a custom implementation that goes beyond simple parameter sweeping.


How To Use
  1. Apply the indicator to any chart (works on all instruments and timeframes).
  2. Green zones below price = support. Red zones above price = resistance.
  3. Wider/more opaque zones indicate stronger historical price concentration (more data points in that cluster).
  4. Use the "Lookback Period" input to match your trading style: shorter for scalping (50–150 bars), longer for swing/position trading (300–2000 bars).
  5. Leave "Manual Zone Adjustment" at 0 for fully automatic operation, or increase it to add more granular zones.
  6. Combine with your own entry/exit methodology — these zones identify where price may react, not how it will react.


Inputs
  • Use All Available History: Analyzes up to 5000 bars. Recommended for daily/weekly charts only due to performance considerations.
  • Lookback Period: Number of bars to analyze (50–5000). Controls how much historical data feeds into the clustering algorithm.
  • Manual Zone Adjustment: Adds extra zones beyond the automatically determined optimal count (0 = fully automatic).


Important Notes
  • This indicator identifies zones of historical price interest — it does not predict future price movement.
  • No indicator guarantees profitable trades. Always use proper risk management.
  • Past performance and historical price patterns do not guarantee future results.
  • Best used as a confluence tool alongside your existing trading methodology.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.