BB Machine Learning - Pattern Recognition
Feb 22, 2026

The BB Machine Learning - Pattern Recognition indicator analyzes historical price behavior at Bollinger Band extremes using K-Nearest Neighbors (KNN) and candlestick pattern recognition to generate high-probability signals. It adapts to current market conditions by learning which patterns led to profitable outcomes on specific instruments and timeframes.
Usage
The Usage section describes how the script can be used to identify mean reversion or breakout opportunities. The tool functions by detecting price proximity to Bollinger Band boundaries and qualifying those touches through a machine learning confidence score.
Mean Reversion Trading
When the market is range-bound, users can look for signals at the band extremes. A long signal occurs at the lower band when the KNN model finds historically successful bounce patterns in similar volatility environments. Users typically set the exit target at the middle band (20-period SMA).
Squeeze Breakouts
The indicator tracks "Squeeze" states where volatility is compressed. Long-duration squeezes often precede explosive moves. The machine learning engine calculates a "Squeeze Outlook," providing a historical ratio of bullish versus bearish breakouts to help traders anticipate the eventual direction.
Pattern Validation
Traders can use the dashboard to verify the statistical reliability of specific candlestick patterns (e.g., Pin Bars, Engulfing) on the active chart. If a Bullish Engulfing pattern at the lower band has a 70% historical win rate while a Pin Bar has only 40%, the ML engine will automatically weight signals from the Engulfing pattern more heavily.
Details
The script's architecture is divided into three primary components:
- Volatility Engine: Based on standard Bollinger Bands (20 SMA, 2 STDEV), it calculates derived metrics like %B (price position) and BB Width (volatility level) to categorize the market into Squeeze, Expanding, Contracting, or Normal states.
- KNN Algorithm: The tool describes each price bar using a 10-point normalized feature vector including RSI, volume, body ratio, and %B. When price hits a band extreme, the KNN algorithm searches the last 300+ bars for similar feature vectors. It then measures the historical outcome of those neighbors (up to 10 bars into the future) to determine a confidence score.
- Pattern Recognition: It identifies 8 specific candlestick formations at the bands (Pin Bar, Engulfing, Doji, Rejection, Multi-touch, Band Walk, Breakout Candle, and Strong Close). Each pattern is tracked individually for its historical success rate on the current chart.
Settings
Bollinger Bands
- BB Length: The period for the middle SMA (default 20).
- BB Multiplier: The standard deviation for the upper/lower bands.
- Source: The price data used for calculation (default: close).
Machine Learning
- ML Lookback Bars: The historical depth the KNN model scans for matching patterns.
- Min Confidence %: The minimum threshold required for a signal to trigger (default 60%).
- Min Historical Samples: The minimum number of similar historical instances needed to validate a signal.
- Success % Threshold: The percentage of price movement required in historical data to classify a "neighbor" as a success.
BB State Detection
- Squeeze Threshold %: The width percentage below which the bands are considered to be in a squeeze.
- Expansion Rate: The rate of width increase required to classify the state as "Expanding."
Risk Management
- Stop Loss %: The percentage-based stop level from the entry price.
- Take Profit %: The percentage-based target level from the entry price.
FAQ
How do I interpret the ML Confidence score? The score represents the weighted percentage of similar historical setups that reached the "Success % Threshold" within the defined future candle lookback. Higher percentages indicate stronger historical precedent.
Why are there no signals appearing on my chart? Signals only trigger when price is at a Bollinger Band extreme, the KNN model finds enough historical matches, and the final confidence score exceeds your "Min Confidence %" setting. Try lowering the confidence threshold or increasing the ML lookback.
How can I access the BB Machine Learning - Pattern Recognition 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.

