All indicators

AI-SuperTrend (KNN Machine Learning)

Mar 6, 2026

Static chart image
SignalsMachine LearningMoving AveragesVolatility

The AI-SuperTrend (KNN Machine Learning) indicator integrates a K-Nearest Neighbors (KNN) classification engine into the classic SuperTrend algorithm to validate trend signals and filter market noise.

Usage

The Usage section describes how the script can be used to identify high-probability trend shifts. The indicator combines traditional volatility-based boundaries with statistical consensus to provide more robust signals.

  • Major Signals (▲/▼): These represent high-confidence trend changes. A signal is only plotted when the SuperTrend direction aligns with the AI's predicted direction and the calculated probability exceeds the user-defined threshold.
  • SuperTrend Dots: These indicate standard SuperTrend flips that occur without full AI confirmation. They serve as secondary visual cues for volatility shifts.
  • Probability Labels: At every SuperTrend reversal point, a label displays the AI's estimated confidence (e.g., "Pred 92%"). This allows for a real-time assessment of the historical validity of the current move.
  • Dynamic Bar Coloring: The gradient coloring reflects real-time AI confidence:
    • Blue/Cyan: High Bullish Confidence.
    • Red/Pink: High Bearish Confidence.
    • Gray: Neutral or Indecisive state.

Details

The script treats the market as a multi-dimensional state rather than attempting simple price prediction. It uses a non-parametric KNN "Lazy Learning" algorithm that identifies historical clusters similar to the present market environment.

  • KNN Engine: The model searches the historical database for the $K$ most similar instances using Minkowski Distance (adjustable via the $p$-parameter). Gaussian Weighting ensures that historical neighbors closer to the current state have a larger impact on the prediction.
  • Feature Engineering: The AI analyzes a multi-dimensional feature space including RSI momentum clusters, Moving Average deviations, and Choppiness Index values.
  • PCA Compression: Users can enable Principal Component Analysis to compress correlated features into 3-4 main components, reducing the "Curse of Dimensionality" and focusing the engine on the most impactful data trends.
  • Sampling Stride: To optimize performance, the engine uses a stride mechanism (e.g., checking every 15th bar). This increases the effective historical range of the "Learning Window" without exceeding computational limits.

Settings

SuperTrend

  • ATR Length: The lookback period used for volatility calculations.
  • Factor: The multiplier that determines the distance of the SuperTrend line from the price.

Machine Learning Engine

  • K-Neighbors (K): The number of historical patterns to compare. Smaller values are more sensitive, while larger values provide more stability.
  • Learning Window Size: The total historical lookback where the AI searches for similar neighbors.
  • Stride: The sampling interval for data collection; higher values allow for a wider historical range with fewer calculations.
  • Prediction Threshold: The confidence level (0.1 to 1.0) required to trigger a major signal.

Feature Engineering

  • Feature MA Type: Selects the baseline for deviation measurements (e.g., SMA, EMA, ZLSMA, HMA).
  • Normalizing Window Size: The lookback period for Z-Score normalization to ensure all features are on the same scale.
  • Minkowski Parameter (p): Controls the distance logic (1 for Manhattan, 2 for Euclidean).
  • Shape Parameter: Adjusts the sensitivity of the Gaussian weighting for neighbors.

FAQ

How do I interpret the percentage labels? The percentage represents the weighted consensus of the nearest historical neighbors. If the label shows 90%, it means that based on the current feature vector, 90% of the weighted historical matches resulted in a similar trend direction.

What is the benefit of enabling PCA? PCA (Principal Component Analysis) reduces noise by merging highly correlated features. This helps the KNN engine focus on the primary drivers of price action rather than redundant data points.

How can I access this tool? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.