INVITE-ONLY SCRIPT

kNN Trend Classifier (RSI, CCI, W%R, ADX, EMA)

25
This Pine Script indicator, "kNN Trend Classifier," is a specialized tool for identifying market trends using a combination of classic technical indicators and a simple machine learning approach. The script is designed for traders who want to blend quantitative analysis with visual chart signals to improve decision-making.

At its core, the indicator utilizes six key features: RSI (14), RSI (9), CCI, Williams %R, ADX, and 9-period EMA. Each of these measures different dimensions of momentum, trend strength, and market positioning. These values are normalized to ensure they are fairly compared across different market conditions. For every bar close, the script stores a historical snapshot of these features and uses a k-Nearest Neighbor (kNN) technique to classify the current trend as bullish or bearish. The kNN algorithm works by calculating the Euclidean distance between the present market state and all stored historical states, then referencing the majority label among the closest neighbors to decide on the market regime.

The script also provides powerful customization. Users can adjust the number of neighbors (k) to make signals more reactive or more stable; increase the training window for a deeper historical perspective; and fine-tune the lookback window for feature normalization. Two optional filters—based on volume percentile and ATR volatility—help to screen out signals in low-liquidity or low-volatility periods, reducing false positives and improving reliability.

To modify the behavior, traders should experiment with the inputs: lower k for faster signal changes, raise k or the training window for smoother signals, and adjust normalization length for different levels of trend sensitivity. Activating the volume and volatility filters is highly recommended during choppy markets. Altogether, this script gives users a robust framework to catch bullish or bearish trends with a blend of proven technical analysis and adaptive pattern recognition.

Wyłączenie odpowiedzialności

Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.