AetherEdge KNN Regime Classifier is an innovative memory-based machine learning regime classifier that fully implements Pine Script’s k-Nearest Neighbors (k-NN) algorithm. It memorizes up to 2,000 historical patterns, retrieves the k most similar historical patterns that match the current 8-dimensional feature vector, and classifies the market into 5 regions (uptrend/downtrend/range/breakout/reversal) in real time by majority vote. Forward returns and past win rates for each regime are statistically tracked to provide multidimensional, data-driven trade support.
🔶 Main features
True k-NN implementation: k is tunable from 3 to 50, odd numbers are preferred
Memory bank: Up to 2,000 pattern storage, FIFO auto-discard
Three distance metrics: Euclidean/Manhattan/Cosine
Two voting schemes: majority voting/distance weighted (1/d)
5 regime classification: Trend▲ / Trend▼ / Range / Breakout / Reversal
Forward-looking validation: Validate each pattern against N-bar future returns
8-D feature vector: ADX/DMI/BBW/RSI/Volume/Slope/Position/ROC
Live win rate table: Visualize the statistical edge of each regime
KNN Distance Heatmap: Distance distribution from nearest distance to farthest distance
Voting distribution bar: % bar showing votes by government
Confidence calculation: Automatically derived from voting concentration
Regime background coloring: Instantly visualize regimes across charts
High Confidence Regime Shift Alert: Triggers at Confidence > 85%
🧠 Technology architecture
This metric is a top-of-the-line regime classification engine that fully implements k-NN, the mainstay of memory-based (lazy) learning.
k-NN algorithm:
Compute the query vector q =. [f1, f2, …, f8]
Compute the distance d(q, m_i) to all memory patterns
Select top-k by ascending distance
Vote: argmax_l Σ w_i × [label_i == l]
Distance metric:
Euclid: √Σ(q_i – m_i)² — standard geometry
Manhattan: Σ|q_i – m_i| — strong against outliers
Cosine: 1 – (q·m)/(|q||m|) — direction-oriented
Weighting scheme:
Majority: simple vote
Distance weighting: w = 1/(d + ε) — closer = stronger
Feature engineering (8-D):
f1: Strength of ADX (presence of trend)
f2: DMI differential (direction)
f3: BBW ratio (volatility expansion)
f4: Normalized RSI (Momentum)
f5: Volume Z-score (liquidity)
f6: Linear regression slope (structural slope)
f7: Range position (within height and low range)
f8: ROC (rate of change)
Institutional labeling rules:
Breakout: BBW > 1.5 x avg and Volume > 1.8 x avg and |ROC| > 1.0
Inversion: RSI extreme value AND ROC sign inversion
Uptrend: ADX > 25 AND DI+ > DI- AND Slope > 0
Downtrend: ADX > 25 AND DI-> DI+ AND Slope < 0
Range: ADX < 18 and BBW < 1.2×Avg.
Prospective validation: Wins and losses are determined after N (default 5) bars
Memory management: Staging queue → commit after transfer window → FIFO when exceeds size
⚙️ Recommended settings and tuning guide
Encryption default:
BTC (4H–D): k=15, memory=500, forward=5 (standard)
ETH (1H–4H): k=11, cosine, forward=8
SOL (high volume): k=21, Manhattan (strong outliers)
XRP (range heavy): k=9, Forward=3 for short horizon edges
k tuning:
k=3~7: High sensitivity, lots of noise
k=11–15: Balanced (recommended)
k=21–31: smooth, rare patterns may be diluted
Memory size:
300: Lightweight, focused on recent trends
500: Standard
1000-2000: Long-term statistics, heavy computing
Forward bar:
3: Scalping
5: Standard
10–15: Focus on swing
Select distance metric:
Euclid: standard, balanced
Manhattan: Lots of assets, lots of outliers.
Cosine: Focus of pattern shape, independent of size
💡 Actual usage
Trend ▲ + Confidence > 70%: Optimal trend following entry
Breakout detected: Activate volatility breakout strategy
Reversal warning: reduce trend following and consider countertrends
Range: Range/grid strategy adaptation
Win Probability Table Analysis: Discover the statistically dominant regime of your assets.
Avg Ret monitoring: Trend ▲ is high +Avg Ret = trend following enabled
Confidence < 50%: Voting dispersion, government opacity - reduced size
Heatmap Green Dominant: Rich Similar Patterns, High Prediction Confidence
Heatmap red predominates: Uncharted territory – proceed with caution
Aether Edge Synergy:
NeuraNet Prediction: KNN Trend▲ + NeuraNet > 0.7 = Dual AI Confidence
Self-evolving S/R grid: breakout regime + line breakthrough = strong entry
All-in-one dashboard: High confidence + KNN trust = ultimate collaboration
Multi TF: 4H KNN regime → 1H strategy selection → 15M precision entry
⚠️Important notes
Learning reset: memory is cleared when reloading the chart. Rebuild required
Minimum Sample (50): Previously, classification was disabled. Waiting phase is required
FIFO memory: old patterns are automatically discarded due to regime adaptation
Computation load: Memory=2000 + k=50 is heavy. Use 500/15 for lower specs
Feature NaN: Feature is initially undefined. Accumulation starts after structLen+50 bars
Rare regime: Reversals/breakouts occur rarely. Small N = unstable statistics
Forward Window Lag: Modern N-bar not yet labeled. memory commit delay
🚨 Disclaimer
This indicator is a machine learning demonstration provided for educational and research purposes only and does not constitute financial advice. k-NN classification results are based on statistical similarity to past patterns and do not guarantee future profits. Reliability varies depending on market conditions, asset and time frame. Combine independent analysis with appropriate risk management.
