RSI Prediction by Range Segmentation [LuxAlgo]The RSI Prediction by Range Segmentation indicator projects a future path for the Relative Strength Index (RSI) by analyzing and averaging historical patterns that originated from similar RSI levels. This tool provides a probabilistic forecast based on how the RSI has historically behaved after reaching specific value segments.
🔶 USAGE
The indicator segments the RSI range (0-100) into multiple horizontal zones. When the current RSI value falls into a specific zone, the script identifies all historical instances where the RSI was in that same zone and calculates the average path it took over a subsequent period.
Users can observe the dynamic polyline forecast extending from the current RSI value to anticipate potential overbought or oversold conditions before they occur. The RSI line itself changes color based on its position relative to the 50 level, providing an immediate visual cue for bullish or bearish momentum.
🔹 Range Segmentation
The RSI scale is divided into "Range Segments" (e.g., 10 segments of 10 points each). This allows the indicator to categorize market momentum into specific states. By increasing the number of segments, you make the historical matching more precise but may have fewer historical samples to average. A step-line is plotted to visualize the base of the current segment being analyzed.
🔹 The Forecast
The forecast is generated only on the most recent bar using a polyline. It looks at the current RSI segment, retrieves the "Historical Limit" of stored patterns for that specific segment, and plots the mathematical average of those paths. The forecast color is dynamic: it appears bullish if the predicted endpoint is higher than the current RSI, and bearish if it is lower.
🔹 Overbought/Oversold Fills
To highlight extreme momentum, the script includes conditional vertical gradient fills. When the RSI rises above the user-defined Overbought Level, a green gradient fills the space between the RSI and the level. Conversely, when it drops below the Oversold Level, a red gradient appears.
🔶 DETAILS
The script utilizes User-Defined Types (UDTs) to store sequences of RSI values (Segments) within specific RangeData objects. This architecture allows the script to efficiently manage memory while maintaining a deep history of price momentum patterns.
Every time a new bar is processed, the script "looks back" at a pattern of a specific length and stores it in the bucket corresponding to where that pattern started (the anchor point). This creates a library of outcomes categorized by their starting momentum state, which is then accessed on the real-time bar to generate the forecast.
🔶 SETTINGS
🔹 General Settings
Historical Limit : Determines the maximum number of historical segments stored for each RSI range. A higher limit provides a more "smoothed" average by including more historical data.
Forecast Length : The number of bars into the future the prediction will extend. This also defines the length of the historical patterns being recorded.
Range Segments : The number of divisions for the 0-100 RSI scale. For example, setting this to 10 creates segments of 10 units (0-10, 10-20, etc.).
RSI Length : The lookback period for the standard RSI calculation.
🔹 Levels
Overbought Level : The threshold above which the RSI is considered overbought and the bullish gradient fill is triggered.
Oversold Level : The threshold below which the RSI is considered oversold and the bearish gradient fill is triggered.
🔹 Colors
Bullish Color : The color used for the RSI line (when > 50), the overbought gradient, and bullish forecasts.
Bearish Color : The color used for the RSI line (when < 50), the oversold gradient, and bearish forecasts.
Level Color : The color of the Overbought, Oversold, and Center (50) horizontal levels.
Pine Script®指標






















