Machine Learning BBPct
Aug 18, 2025

The Machine Learning BBPct indicator provides an enhanced Bollinger Band %B oscillator integrated with a simplified K-Nearest Neighbors (KNN) pattern matcher to reduce noise and provide context-aware market state descriptions. By comparing current volatility, momentum, and volume features to historical analogs, the tool blends past consensus with raw %B values to improve signal clarity.
Usage
The Usage section focuses on interpreting the hybrid oscillator and its adaptive features for market analysis. Users can utilize the script to identify overbought/oversold conditions while benefiting from an ML layer that attempts to filter out "whippy" price action common in fast-moving regimes.
- Mean Reversion: In range-bound markets, use the ML-smoothed %B and adaptive thresholds to identify potential reversal points with fewer false signals than standard %B.
- Trend Analysis: During persistent trends, observe how the KNN blend maintains the signal line within extreme zones. A high ML confidence score suggests historical support for the current price positioning.
- Contextual Filtering: The "ML Prediction" dots provide a secondary visual guide. When these dots turn bright white, it indicates high model confidence (>0.7), suggesting the current market state strongly matches historical patterns.
Details
The script operates through a multi-step logic process that begins with standard Bollinger Band %B calculations.
- Feature Engineering: The KNN model constructs a "feature vector" for each bar using normalized values for %B, band width (volatility), price momentum (ROC), volume momentum, and price position within the bands.
- KNN Logic: The script uses Euclidean distance to rank the most similar recent bars within a specified historical window. It calculates an inverse-distance weighted average of the neighbors' prior %B values to generate a prediction.
- Adaptive Filtering: The "Adaptive" filter uses the model's confidence to modulate smoothing. High confidence leads to stronger reliance on the ML estimate, while low confidence reduces its influence.
- Regime Awareness: The tool calculates a volatility regime (ATR relative to its SMA) to nudge the overbought/oversold thresholds. This ensures that extreme readings are comparable across high and low volatility environments.
Settings
BBPct Settings
- Price Source: Determines the data point (e.g., Close) used for %B calculation.
- Calculation Period: Sets the lookback for the SMA basis and standard deviation.
- Multiplier: Adjusts the standard deviation width of the bands.
- Smoothing (Toggle/Type/Length): Allows for pre-processing the %B stream using various moving averages like EMA, HMA, or TEMA.
KNN Machine Learning
- Enable KNN: Toggles the machine learning layer on or off.
- K (Neighbors): The number of historical analogs used to generate the prediction.
- Historical Period: The size of the search window for finding neighbors.
- ML Weight: Controls the blend between raw %B (0.0) and the KNN estimate (1.0).
- Number of Features: Selects between 2 to 5 data points to include in the pattern matching.
Filtering & Optimization
- Filter Method: Selects between None, Adaptive, Kalman, or Hull smoothing for the final output.
- Enable Self-Optimization: Enables a rolling comparison of parameter sets to find the most stable K value.
- Adaptive Thresholds: Automatically adjusts OB/OS lines based on current volatility levels.
FAQ
What do the signal labels like "Early Buy" mean? These are heuristic markers based on a short-term slope and acceleration probe. They indicate that the oscillator is on track to cross a threshold soon, provided momentum remains consistent.
How is the "Win Rate" calculated? The script includes an informational tracker that scores past signal outcomes based on simple target, stop, and time-out logic. This is a diagnostic tool and not a robust backtest.
How can I access this 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.

