OPEN-SOURCE SCRIPT
MYND KNN Pattern Match Classifier v1.1

MYND KNN Pattern Match Classifier [v1.1]
A genuine machine-learning pattern matcher: it finds the historical bars that looked most like right now, and reports what actually happened next - a real "have I seen this setup before" read, not a black-box promise.
WHAT IT DOES
Every bar, this indicator builds a small fingerprint of current conditions (momentum, rate of change, volume, and volatility, each normalized to a comparable scale) and compares it against a rolling buffer of past bars whose outcomes are already fully known. The K most similar historical bars vote on a 0-100 Bullish Probability Score. It also grades itself two different ways: a broad Directional Lean Accuracy across every bar, and a Signal Accuracy that grades only the bars where an actual Bullish/Bearish alert fired - the number that actually answers whether the alerts you'd act on have been any good.
HOW IT WORKS
This uses K-Nearest-Neighbors (KNN) classification, the same technique behind several well-known published TradingView machine-learning scripts - not a literal AI model, which Pine Script cannot run internally. Four features go into each bar's comparison: RSI, rate of change, volume, and ATR%, each z-scored over a shared lookback so none of them dominate just because of their raw units. A weighted Euclidean distance finds the K closest historical matches, and both their outcomes and their actual returns are blended - using the same optional distance weighting throughout - into the final score and the average-return statistic.
Because a label requires knowing what actually happened afterward, new historical entries are only added to the comparison buffer once their outcome has genuinely resolved. There's no look-ahead: every point the tool compares against is a fully realized piece of history.
A transparency note worth knowing: a new labeled entry is added every bar, and each one covers a multi-bar forward outcome, so consecutive entries overlap heavily rather than being fully independent observations. The sample-size number on the dashboard is a nominal count, not a count of independent data points - the tool's default settings account for this, and the settings panel explains it directly.
KEY FEATURES
Two separate self-tracking accuracy stats - Directional Lean Accuracy (a broad, always-on health check) and Signal Accuracy (grades only the actual alerts) - with a dedicated warning alert tied specifically to Signal Accuracy dropping below a level you choose. Fully adjustable feature weights, so you can emphasize whichever ingredient matters most for your style. A continuous, distance-weighted vote rather than a hard cutoff, so the score moves smoothly. Nearly every input carries an explanatory tooltip. Full color, plot style, and table customization.
HOW TO USE IT
Expect a warm-up period after adding this to a new chart - the historical sample starts empty and needs time to build before the score is meaningful, and Signal Accuracy takes longer still since it only grades actual fired alerts. Use the Probability Score as a directional lean or filter alongside your own entry method, not as a standalone trigger; a KNN read that agrees with an independent signal is a stronger case than either alone. Check Signal Accuracy specifically before leaning on a signal - it's the metric that reflects the actual alerts you'd be acting on, not just the raw score's overall lean.
SETTINGS WORTH TUNING FIRST
K Nearest Neighbors and Max Historical Sample Size - raise either for a smoother, steadier score; lower for one that reacts faster. Feature Weights - if one ingredient seems to be adding noise rather than signal on a given symbol, lower its weight toward zero. Prediction Horizon - should roughly match your actual holding period, since that's the window the score is implicitly forecasting.
ALERTS
All 5 alerts use TradingView's standard alertcondition() system - no special setup required. Add Alert, choose this indicator, and pick the named condition from the dropdown.
This is classical statistical pattern matching, not genuine predictive intelligence - it reports how similar-looking historical setups actually resolved, which is a real edge but not a guarantee, and results are symbol- and timeframe-specific by design. This tool is provided for informational and educational purposes and does not constitute financial advice. Trading involves risk; past performance and historical patterns do not guarantee future results.
A genuine machine-learning pattern matcher: it finds the historical bars that looked most like right now, and reports what actually happened next - a real "have I seen this setup before" read, not a black-box promise.
WHAT IT DOES
Every bar, this indicator builds a small fingerprint of current conditions (momentum, rate of change, volume, and volatility, each normalized to a comparable scale) and compares it against a rolling buffer of past bars whose outcomes are already fully known. The K most similar historical bars vote on a 0-100 Bullish Probability Score. It also grades itself two different ways: a broad Directional Lean Accuracy across every bar, and a Signal Accuracy that grades only the bars where an actual Bullish/Bearish alert fired - the number that actually answers whether the alerts you'd act on have been any good.
HOW IT WORKS
This uses K-Nearest-Neighbors (KNN) classification, the same technique behind several well-known published TradingView machine-learning scripts - not a literal AI model, which Pine Script cannot run internally. Four features go into each bar's comparison: RSI, rate of change, volume, and ATR%, each z-scored over a shared lookback so none of them dominate just because of their raw units. A weighted Euclidean distance finds the K closest historical matches, and both their outcomes and their actual returns are blended - using the same optional distance weighting throughout - into the final score and the average-return statistic.
Because a label requires knowing what actually happened afterward, new historical entries are only added to the comparison buffer once their outcome has genuinely resolved. There's no look-ahead: every point the tool compares against is a fully realized piece of history.
A transparency note worth knowing: a new labeled entry is added every bar, and each one covers a multi-bar forward outcome, so consecutive entries overlap heavily rather than being fully independent observations. The sample-size number on the dashboard is a nominal count, not a count of independent data points - the tool's default settings account for this, and the settings panel explains it directly.
KEY FEATURES
Two separate self-tracking accuracy stats - Directional Lean Accuracy (a broad, always-on health check) and Signal Accuracy (grades only the actual alerts) - with a dedicated warning alert tied specifically to Signal Accuracy dropping below a level you choose. Fully adjustable feature weights, so you can emphasize whichever ingredient matters most for your style. A continuous, distance-weighted vote rather than a hard cutoff, so the score moves smoothly. Nearly every input carries an explanatory tooltip. Full color, plot style, and table customization.
HOW TO USE IT
Expect a warm-up period after adding this to a new chart - the historical sample starts empty and needs time to build before the score is meaningful, and Signal Accuracy takes longer still since it only grades actual fired alerts. Use the Probability Score as a directional lean or filter alongside your own entry method, not as a standalone trigger; a KNN read that agrees with an independent signal is a stronger case than either alone. Check Signal Accuracy specifically before leaning on a signal - it's the metric that reflects the actual alerts you'd be acting on, not just the raw score's overall lean.
SETTINGS WORTH TUNING FIRST
K Nearest Neighbors and Max Historical Sample Size - raise either for a smoother, steadier score; lower for one that reacts faster. Feature Weights - if one ingredient seems to be adding noise rather than signal on a given symbol, lower its weight toward zero. Prediction Horizon - should roughly match your actual holding period, since that's the window the score is implicitly forecasting.
ALERTS
All 5 alerts use TradingView's standard alertcondition() system - no special setup required. Add Alert, choose this indicator, and pick the named condition from the dropdown.
This is classical statistical pattern matching, not genuine predictive intelligence - it reports how similar-looking historical setups actually resolved, which is a real edge but not a guarantee, and results are symbol- and timeframe-specific by design. This tool is provided for informational and educational purposes and does not constitute financial advice. Trading involves risk; past performance and historical patterns do not guarantee future results.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.