OPEN-SOURCE SCRIPT
Diupdate Reversal Probability & Signals

This indicator is designed to forecast critical market turning points by predicting the formation of TOPs (Pivot Highs) and BOTTOMs (Pivot Lows).
To achieve this, the script utilizes a simplified K-Nearest Neighbors (KNN) machine learning algorithm built directly within Pine Script. By analyzing a wide spectrum of Commodity Channel Index (CCI) values, it calculates the real-time probability that the current price action will result in a structural Pivot reversal.
How It Works (The Engine)

The script functions as a real-time pattern recognition engine. It operates in three main steps:
Feature Extraction: It concurrently calculates 8 different lengths of the CCI (from very short to long-term periods like 10 to 200). This acts as the feature set of the current market momentum.
Data Collection (Training): Whenever the market makes a significant structural Top or Bottom (based on Pivot points), the script records the specific state of those 8 CCIs at that exact moment. It also collects random "non-target" samples to build a balanced historical database.
KNN Classification (Prediction): On every new bar, the algorithm calculates the mathematical Euclidean distance between the current 8 CCI values and the historically saved samples. It looks at the "K" nearest historical neighbors. If the majority of those closest historical neighbors were market bottoms, the indicator outputs a high "Bottom Probability."
Key Features
Dynamic K-Value Adjustment: To ensure stable and accurate calculations even shortly after applying the indicator (when the historical sample pool is still growing), the "K" value dynamically scales down based on the available data size and automatically adjusts to odd numbers to prevent tie-breaking ambiguity.
Two-Step Smart Signal Logic: To prevent premature entries during strong, ongoing trends, this script uses a dual-threshold confirmation system:
Standby: The probability must first surge above an Upper Threshold (Default: 80%), indicating extreme conditions.
Trigger: The actual signal is only plotted when the probability peaks and subsequently drops below a Lower Threshold (Default: 50%). This confirms that the extreme momentum has broken and the reversal is underway.
Target Selection: Easily switch the engine's focus between predicting a "BOTTOM" or a "TOP" via the settings panel.
Visual Enhancements & Alerts: Includes intuitive dynamic bar coloring (changing based on probability intensity), a clear histogram, distinct signal shapes on the chart, and fully integrated alert conditions for automation.
Settings & Configuration
Prediction Target: Toggle between BOTTOM (Pivot Lows) and TOP (Pivot Highs).
Feature Parameters (CCI): Customize the 8 periods used for momentum extraction. Default settings range from 10 to 200 to capture micro-fluctuations up to macro-trends.
KNN Model Settings: * K-Value: The baseline number of nearest neighbors to compare.
Max Samples: The memory limit for historical data points (higher = more stability, but heavier computation).
Signal Settings: Customize the Upper and Lower thresholds for the two-step signal generation.
How to Trade with It
Select your target: Decide if you are looking for long opportunities (BOTTOM) or short opportunities (TOP).
Watch the Buildup: Observe the histogram or candlestick colors. When the probability goes above 80%, the market is showing conditions highly similar to historical reversals. Do not enter yet.
Wait for the Trigger: Wait for the momentum to break. When the probability drops back below the 50% threshold, a triangle shape will appear on the chart. This is your signal that the reversal pattern is executing.
Disclaimer:
This script uses historical pattern matching and experimental mathematical models. It does not guarantee future results. Please use it in conjunction with broader market context, other technical indicators, and strict risk management.
To achieve this, the script utilizes a simplified K-Nearest Neighbors (KNN) machine learning algorithm built directly within Pine Script. By analyzing a wide spectrum of Commodity Channel Index (CCI) values, it calculates the real-time probability that the current price action will result in a structural Pivot reversal.
How It Works (The Engine)
The script functions as a real-time pattern recognition engine. It operates in three main steps:
Feature Extraction: It concurrently calculates 8 different lengths of the CCI (from very short to long-term periods like 10 to 200). This acts as the feature set of the current market momentum.
Data Collection (Training): Whenever the market makes a significant structural Top or Bottom (based on Pivot points), the script records the specific state of those 8 CCIs at that exact moment. It also collects random "non-target" samples to build a balanced historical database.
KNN Classification (Prediction): On every new bar, the algorithm calculates the mathematical Euclidean distance between the current 8 CCI values and the historically saved samples. It looks at the "K" nearest historical neighbors. If the majority of those closest historical neighbors were market bottoms, the indicator outputs a high "Bottom Probability."
Key Features
Dynamic K-Value Adjustment: To ensure stable and accurate calculations even shortly after applying the indicator (when the historical sample pool is still growing), the "K" value dynamically scales down based on the available data size and automatically adjusts to odd numbers to prevent tie-breaking ambiguity.
Two-Step Smart Signal Logic: To prevent premature entries during strong, ongoing trends, this script uses a dual-threshold confirmation system:
Standby: The probability must first surge above an Upper Threshold (Default: 80%), indicating extreme conditions.
Trigger: The actual signal is only plotted when the probability peaks and subsequently drops below a Lower Threshold (Default: 50%). This confirms that the extreme momentum has broken and the reversal is underway.
Target Selection: Easily switch the engine's focus between predicting a "BOTTOM" or a "TOP" via the settings panel.
Visual Enhancements & Alerts: Includes intuitive dynamic bar coloring (changing based on probability intensity), a clear histogram, distinct signal shapes on the chart, and fully integrated alert conditions for automation.
Settings & Configuration
Prediction Target: Toggle between BOTTOM (Pivot Lows) and TOP (Pivot Highs).
Feature Parameters (CCI): Customize the 8 periods used for momentum extraction. Default settings range from 10 to 200 to capture micro-fluctuations up to macro-trends.
KNN Model Settings: * K-Value: The baseline number of nearest neighbors to compare.
Max Samples: The memory limit for historical data points (higher = more stability, but heavier computation).
Signal Settings: Customize the Upper and Lower thresholds for the two-step signal generation.
How to Trade with It
Select your target: Decide if you are looking for long opportunities (BOTTOM) or short opportunities (TOP).
Watch the Buildup: Observe the histogram or candlestick colors. When the probability goes above 80%, the market is showing conditions highly similar to historical reversals. Do not enter yet.
Wait for the Trigger: Wait for the momentum to break. When the probability drops back below the 50% threshold, a triangle shape will appear on the chart. This is your signal that the reversal pattern is executing.
Disclaimer:
This script uses historical pattern matching and experimental mathematical models. It does not guarantee future results. Please use it in conjunction with broader market context, other technical indicators, and strict risk management.
Catatan Rilis
Optimized initial settings as below:CCI Length:10,20,30,40,50,80,100,200→20,25,30,40,50,100,200,400
Pivot Right: 2→5, Pivot Left:2→5,Lower threshold:50→80
Catatan Rilis
increased initial K to 80.Catatan Rilis
Updated the CCI calculation logic.Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.