Machine Learning PSAR

Feb 23, 2026

Static chart image
Signals
Machine Learning
Moving Averages
Volatility

The Machine Learning PSAR indicator is a regime-aware trend reversal system that tracks directional price movement through an adaptive Parabolic SAR, utilizing K-Means clustering for market regime detection and K-Nearest Neighbors (KNN) for signal validation. By dynamically adjusting acceleration parameters based on market context, it aims to provide more responsive signals in trending environments while reducing noise during choppy conditions.

Usage

The Usage section describes how the script can be used to identify trend reversals and quantify signal strength.

  • Trend Identification: A bullish state is established when price closes above the SAR (colored blue), while a bearish state occurs when price closes below the SAR (colored red). The SAR line acts as a dynamic trailing stop.
  • Confidence Filtering: Each reversal (flip) is assigned a confidence score (0–100%) based on historical similarities. High-confidence flips (typically 70%+) suggest a stronger historical precedent for success, while low-confidence flips are displayed with fainter visual fills.
  • Regime Awareness: Numeric labels (1, 2, or 3) indicate the current market state. Label 3 represents a trending market (aggressive parameters), Label 2 is neutral, and Label 1 represents a choppy market (conservative parameters).
  • Visual Interpretation: The opacity of the fill between the price and the SAR line reflects the KNN confidence score; denser fills indicate higher conviction.

Details

The script integrates classical technical analysis with machine learning concepts to improve the reliability of the Parabolic SAR.

  • Adaptive PSAR Engine: Uses standard PSAR logic but replaces fixed increments with dynamic values scaled by market regime. It includes an optional exponential smoothing for the Acceleration Factor (AF).
  • K-Means Regime Classifier: This module measures the frequency of SAR flips over a training period. It categorizes the market into one of three regimes (Choppy, Neutral, Trending) by comparing current flip frequency against historical percentiles.
  • KNN Signal Validator: Upon a trend flip, the script constructs a five-dimensional feature vector (including trend duration and AF progress) and searches for the "K" most similar historical instances. The signal's confidence is derived from the outcomes of these historical neighbors.
  • Kalman Smoothing Layer: A recursive Kalman filter is applied to the final output to reduce visual "stair-stepping" while maintaining zero lag during actual trend reversals.

Settings

PSAR Settings

  • Base AF Start: The initial Acceleration Factor for a new trend.
  • Base AF Increment: The rate at which the AF increases as the trend persists.
  • Base AF Maximum: The upper limit for the Acceleration Factor.

K-Means Regime Detection

  • Enable K-Means Adaptation: Toggles the dynamic adjustment of AF parameters based on market regime.
  • Training Data Period: The lookback period used to classify flip frequency.
  • Choppy/Trending Regime Percentile: Thresholds used to define the boundaries between market states.

KNN Signal Validation

  • Enable KNN Signal Scoring: Toggles the historical validation of reversal signals.
  • K - Number of Neighbors: The number of historical matches used to calculate confidence.
  • Historical Lookback Period: The range of historical data scanned for similar setups.
  • Minimum Confidence Filter: The threshold for classifying a flip as high-confidence.

Smoothing & Filters

  • Enable AF Smoothing: Uses exponential smoothing for more fluid AF transitions.
  • Enable Kalman Filter: Applies recursive smoothing to the displayed SAR dots.
  • Enable Minimum Bars Filter: Requires a trend to last a set number of bars before allowing a reversal.

FAQ

How do I interpret the regime numbers on the chart? The numbers 1, 2, and 3 represent Choppy, Neutral, and Trending regimes respectively. These are determined by how frequently the market has been reversing lately; fewer reversals typically lead to a Trending (3) classification.

What is the difference between a high-confidence and low-confidence flip? A high-confidence flip occurs when the KNN model finds that similar historical price behaviors frequently led to successful trend continuations. Low-confidence flips suggest that historical outcomes were mixed or unsuccessful in similar contexts.

How do I access this indicator? 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
ninjatraderNinjaTrader
metatrader4MetaTrader 4/5
thinkorswimThinkorswim

Unlock Unlimited Access to the LuxAlgo Library

Upgrade your plan to get all indicators, strategies, charts, and full access to Quant, our AI agent.

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.