AI-SuperTrend (KNN Machine Learning)

Mar 6, 2026

Static chart image
Signals
Machine Learning
Moving Averages
Volatility

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 access on the following platforms
tradingviewSymbolTradingView
Open in your browser

This in-app browser is not compatible with Get Access from the library.

Tap the menu (...) at the top of your screen and select "Open in Browser", "Open in Safari", or "Open in Chrome" to continue.

ninjatraderNinjaTrader
Open in your browser

This in-app browser is not compatible with Get Access from the library.

Tap the menu (...) at the top of your screen and select "Open in Browser", "Open in Safari", or "Open in Chrome" to continue.

metatrader4MetaTrader 4/5
Open in your browser

This in-app browser is not compatible with Get Access from the library.

Tap the menu (...) at the top of your screen and select "Open in Browser", "Open in Safari", or "Open in Chrome" to continue.

thinkorswimThinkorswim
Open in your browser

This in-app browser is not compatible with Get Access from the library.

Tap the menu (...) at the top of your screen and select "Open in Browser", "Open in Safari", or "Open in Chrome" to continue.

Trading & investing are risky and many will lose money in connection with trading and investing activities. All content on this site is not intended to, and should not be, construed as financial advice. Decisions to buy, sell, hold or trade in securities, commodities and other investments involve risk and are best made based on the advice of qualified financial professionals. Past performance does not guarantee future results.

Hypothetical or Simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, including, but not limited to, lack of liquidity. Simulated trading programs in general are designed with the benefit of hindsight, and are based on historical information. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

Testimonials appearing on this website may not be representative of other clients or customers and is not a guarantee of future performance or success.

As a provider of technical analysis tools and strategies, we do not have access to the personal trading accounts or brokerage statements of our customers. As a result, we have no reason to believe our customers perform better or worse than traders as a whole based on any content, tool, or platform feature we provide.

Charts used on this site are by TradingView in which the majority of our technical indicators are built on. TradingView® is a registered trademark of TradingView, Inc. www.TradingView.com TradingView® has no affiliation with the owner, developer, or provider of the Services described herein.

Market data is provided by CBOE, CME Group, BarChart, Massive, CoinAPI. Select U.S. equities data is provided through Massive. CBOE BZX real-time U.S. equities data is licensed from CBOE and provided through BarChart. Real-time futures data is licensed from CME Group and provided through BarChart. Select cryptocurrency data, including major coins, is provided through CoinAPI. All data is provided “as is” and should be verified independently for trading purposes.

This does not represent our full Disclaimer. Please read our full disclaimer.

© 2026 LuxAlgo Global, LLC.