Machine Learning Pivot Points (KNN)
Mar 7, 2026

The Machine Learning Pivot Points (KNN) indicator utilizes a K-Nearest Neighbors (KNN) algorithm and linear regression slopes to predict potential market reversals by comparing current price movement to a localized database of historical pivot signatures.
Usage
The Usage section describes how the script can be used to identify potential market turns before they are fully confirmed. The indicator identifies historical pivot highs and lows and extracts their "slope signature"—the mathematical curve of price leading into the turn.
Signal Interpretation
- Approaching Pivot High: Triggered when the current rolling slope shows high mathematical similarity to historical peak signatures. This is visualized with red glowing polyline geometry and a bearish bias in the dashboard.
- Approaching Pivot Low: Triggered when the current rolling slope matches the signature of historical troughs. This is visualized with green glowing polyline geometry and a bullish bias in the dashboard.
Dashboard Analysis
The script includes two primary tables for real-time analysis:
- Directional Helper: Displays the live KNN bias and a confidence metric. The confidence percentage represents cluster similarity; a value above 90% indicates the current price curve is nearly identical to the most significant historical reversals in the current lookback.
- Backtest Table: Provides a performance summary for the specific ticker, including the success rate of signals and the average price move following a prediction.
Details
The core of the system is the Historical Slope Function. Unlike static machine learning models, this script "trains" itself dynamically on the active chart. When a pivot (defined by the Bars Left/Right setting) is confirmed, the script calculates the linear regression slope of the preceding 20 bars and stores it in a dynamic array.
As new price data arrives, the KNN algorithm calculates the Euclidean distance between the current rolling slope and the stored historical slopes. By classifying the current movement based on its proximity to either the "High" or "Low" slope clusters, the indicator can flag a potential reversal while the price is still in motion. To optimize performance and visual clarity, the script uses v6 Polyline Geometry for recent signals and reverts to standard shapes for deep historical data.
Settings
Pivots
- Bars Left/Right: Defines the number of bars required on either side to confirm a historical pivot point for the memory bank.
Machine Learning Parameters
- KNN Clusters (K): Determines how many of the most similar past events are averaged for the prediction. Higher values make the model stricter and signals less frequent.
- Pivot Window: Sets the lookback length for the linear regression slope calculation. It is recommended to set this to at least double the "Bars Left/Right" value to capture a complete curve signature.
Helper Tables
- Show Directional Helper (Top Right): Toggles the visibility of the real-time bias and confidence table.
- Show backtest table: Toggles the visibility of the performance metrics table in the bottom right.
FAQ
How do I access Machine Learning Pivot Points (KNN)?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Why do some signals appear as triangles instead of glowing lines?
Because of platform limits on polyline geometry, the script uses glowing polylines for the most recent signals and reverts to standard triangles for older historical data to maintain performance and visibility across the chart.
What does the "Confidence" metric represent?
Confidence measures how much closer the current price slope is to one cluster (e.g., historical lows) compared to the other (e.g., historical highs). A higher percentage indicates a stronger mathematical match to one specific type of historical reversal.
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.

