INVITE-ONLY SCRIPT
kNN Trend Classifier (RSI, CCI, W%R, ADX, EMA)

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.
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.
僅限邀請腳本
只有經作者批准的使用者才能訪問此腳本。您需要申請並獲得使用權限。該權限通常在付款後授予。如欲了解更多詳情,請依照以下作者的說明操作,或直接聯絡jaydesaigu。
除非您完全信任其作者並了解腳本的工作原理,否則TradingView不建議您付費或使用腳本。您也可以在我們的社群腳本中找到免費的開源替代方案。
作者的說明
Adjust parameters for best results.
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
僅限邀請腳本
只有經作者批准的使用者才能訪問此腳本。您需要申請並獲得使用權限。該權限通常在付款後授予。如欲了解更多詳情,請依照以下作者的說明操作,或直接聯絡jaydesaigu。
除非您完全信任其作者並了解腳本的工作原理,否則TradingView不建議您付費或使用腳本。您也可以在我們的社群腳本中找到免費的開源替代方案。
作者的說明
Adjust parameters for best results.
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。