
A k-nearest neighbors (k-NN) model that predicts stock prices by comparing current market conditions with historical data points using distance calculations and price estimation.
Explore complementary indicator rolesHow it works
The k-NN model begins by extracting a window of past price changes to capture the market's historical context. It then calculates the distance between the current market conditions and historical data points, measuring their similarity.
After computing these distances, the algorithm selects 'k' closest neighbors from the historical data. It generates a price forecast by taking the average price of these selected neighbors and then normalizes the prediction using Z-score scaling to enhance robustness and comparability.
Why it may be useful
The k-NN model offers traders a data-driven approach to understanding market dynamics by identifying similar historical market conditions. By leveraging past price patterns, it provides a predictive framework that can help traders anticipate potential future price movements with a statistical foundation.
The method's strength lies in its ability to adapt to different market contexts and its simplicity in comparing current conditions to historical data. By using distance calculations and neighbor selection, it creates a flexible predictive tool that can potentially reveal underlying market trends and patterns.
When to explore it
This signal is most effective when applied to longer timeframes, specifically 8-hour charts for stocks and forex, and 4-hour charts for cryptocurrency markets. It requires a substantial historical dataset to make meaningful comparisons and generate accurate predictions.
Traders should use this model when seeking a comprehensive view of market trends and looking to understand potential price movements based on historical similarities. It works best in markets with consistent patterns and when used as part of a broader analytical strategy, complementing other technical and fundamental analysis tools.
Keep exploring
What we’ve verified
Access, alerts and repainting behaviour have not been independently verified for this indicator. Check the creator’s current publication and settings.
General descriptions and classifications are recovered research. Verified details above identify the specific checks we have completed. Check the creator’s current publication for later changes.



![Machine Learning: Trend Lines [YinYangAlgorithms] chart preview](https://s3.tradingview.com/u/U3CHwiXZ.png?v=1696859377)
![AI Momentum [YinYang] chart preview](https://s3.tradingview.com/n/NKUsm5uR.png?v=1695686677)
![Market Structure MTF Trend [Pt] chart preview](https://s3.tradingview.com/h/hn7xYdd7.png?v=1741900143)
