Overview
The KNN Supertrend Horizon is an advanced machine learning indicator that enhances the classic Supertrend algorithm with k-Nearest Neighbours (kNN) classification. Where the original Supertrend simply uses ATR-based bands to determine trend direction, this indicator uses kNN to analyse multiple features simultaneously including price velocity, volatility regime, volume profile, and momentum to determine whether a trend signal is likely to be reliable or not.
The result is a Supertrend line that adapts dynamically to changing market conditions, avoiding the whipsaw signals that commonly plague simpler ATR-based implementations in choppy, low-volatility environments.
How It Works
The indicator operates in three stages:
- Feature Extraction: For each bar, the algorithm extracts a feature vector consisting of normalised ATR, rate of change, RSI, volume deviation from average, and candle body ratio.
- kNN Classification: The current bar's feature vector is compared to the K most similar historical bars (default K=8). The directional outcome of those historical bars is used to vote on the current bar's likely direction.
- Supertrend Output: The standard Supertrend formula is then applied, but the multiplier is dynamically adjusted based on the kNN confidence score. High-confidence trending conditions tighten the bands; low-confidence choppy conditions widen them.
How to Use
Entry signals:
- Go long when the indicator flips from red to green AND the kNN confidence level is above 60%.
- Go short when the indicator flips from green to red AND the kNN confidence level is above 60%.
- Avoid signals when confidence is below 50% these occur in choppy, directionless markets.
Stop placement: Place stops just beyond the Supertrend line. The line's dynamic width means stops are automatically wider in volatile conditions and tighter in trending conditions.
Best used on: 1H, 4H, and Daily timeframes. Works across Forex, Indices, and Crypto.
Settings
| Parameter | Default | Description |
|---|---|---|
atr_period | 10 | ATR period for Supertrend band calculation |
atr_multiplier | 3.0 | Base ATR multiplier (dynamically adjusted by kNN confidence) |
k_neighbors | 8 | Number of nearest neighbours for kNN voting |
lookback | 200 | Historical bars used to build the kNN training set |
min_confidence | 0.50 | Minimum kNN confidence required to display a signal |
show_confidence | true | Display confidence score as a subplot |
Important Notes
- This indicator does not repaint. All signals are confirmed on bar close.
- The kNN model is recalibrated on every bar using the trailing lookback window. No offline training is required.
- Performance is best on liquid instruments with reliable volume data (avoid thinly traded assets).
- As with all indicators, this tool is for analysis only and does not constitute financial advice.