Support & Resistance AI (K means/median)
Aug 21, 2023

The Support & Resistance AI (K means/median) indicator utilizes unsupervised machine learning clustering algorithms to identify historically significant price zones where reversals or continuations are likely to occur.
Usage
The Usage section describes how the script can be used to identify key market levels through data clustering. Traders can use this tool to determine precise entries, exits, and risk management zones based on statistical density rather than subjective trendlines.
- Directional Trading: When the price is within a cluster zone and the trader expects a continuation, the cluster center serves as a reference point. A stop-loss can be placed at the 1 standard deviation (SD) band surrounding the cluster to define the risk-to-reward ratio.
- Reversal Trading: Cluster centers act as high-probability support and resistance levels. Traders can look for price pivots at these levels to initiate counter-trend positions.
- Cluster Density Analysis: A table in the top-right corner displays the density of each cluster. Higher density percentages indicate that price has historically spent more time at that level, suggesting a "gravitational" pull or stronger significance for future reactions.
Details
The script applies the K-means (or K-median) algorithm to historical price data. The process involves initializing cluster centers, assigning historical bars to the nearest cluster based on Euclidean distance, and iteratively updating the center until the points stabilize.
Unlike traditional support and resistance identification—which relies on manual trendlines, psychological round numbers, or moving averages—the K-clustering approach groups similar price behavior patterns mathematically. By calculating the standard deviation within each cluster, the tool provides a measure of volatility:
- Low Standard Deviation: Indicates price stability within the cluster, allowing for tighter stop-losses.
- High Standard Deviation: Indicates higher volatility, suggesting the need for wider stops to avoid premature exits.
The inclusion of the K-median method addresses a common limitation of standard K-means: sensitivity to outliers. While K-means uses averages, K-median is more robust against extreme price spikes caused by news events or market anomalies.
Settings
- Number of clusters: Selects between 3 to 5 clusters. Fewer clusters (3) are recommended for intraday trading, while more clusters (4-5) are better suited for daily timeframes.
- Cluster Method: Allows switching between "K means" (for data without major outliers) and "K median" (more robust for volatile data).
- Bars back to train on: Determines the historical lookback period used for the clustering calculation.
- Show SD Bands: Toggles the visibility of the 1 standard deviation bands around the cluster centers.
FAQ
How do I interpret the Cluster Density table? The table shows the percentage of data points assigned to each cluster. Higher percentages indicate stronger historical significance, meaning the level has acted as a frequent area of interest for market participants.
What is the benefit of using K-median over K-means? K-median is less sensitive to price outliers. If the historical data contains extreme spikes or flash crashes, K-median will provide a more accurate representation of the "true" support/resistance levels by focusing on the median rather than the average.
How do I access the Support & Resistance AI (K means/median) indicator? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
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.

