OPEN-SOURCE SCRIPT
Indicator Configuration Forecasting [LuxAlgo]

The Indicator Configuration Forecasting tool identifies historical market regimes that share a similar technical configuration to the current market and projects future price action based on those historical outcomes. By encoding multiple technical indicators into a state vector and employing a K-Nearest Neighbors (KNN) search, the script provides a probabilistic forecast including a median path and confidence intervals.
🔶 USAGE
The indicator works by "memorizing" the state of various user-selected technical indicators at every bar. When the current bar's configuration matches or closely resembles a previous historical state, the script records how the price moved in the subsequent N bars from that point in time.
🔹 Forecast Interpretation
🔹 Configuration Strategy
Users can toggle various indicators to define what constitutes a "similar" market state. For example, if only "SMA Cross" and "Supertrend" are enabled, the script will look for historical periods where the trend relationship and SMA positioning were identical to the current bar, regardless of RSI or MACD values.
🔶 DETAILS
The script utilizes a state-encoding methodology to calculate distances between the current market environment and the past. Each enabled indicator is converted into a discrete value (e.g., 1 for bullish, -1 for bearish, 0 for neutral). These values form a vector for the current bar.
The algorithm then scans through the "Historical Lookback" period to find the "Top K" neighbors—the points in history where the vector distance to the current state is minimized. To ensure variety in the forecast, the script includes logic to prevent overlapping matches, ensuring that the selected historical points are distinct events.
Once the matches are identified, the script calculates the percentage returns for the specified "Forecast Horizon (N)" and projects those returns onto the current price to generate the visual forecast.
🔶 SETTINGS
🔹 Parameters
🔹 Indicator Configuration
🔹 Visibility & Style
🔶 USAGE
The indicator works by "memorizing" the state of various user-selected technical indicators at every bar. When the current bar's configuration matches or closely resembles a previous historical state, the script records how the price moved in the subsequent N bars from that point in time.
🔹 Forecast Interpretation
- Median Forecast (Dashed Gray): Represents the 50th percentile (median) of all matched historical outcomes. This is the central tendency of the forecast.
- Upper Bound (Dashed Green): Represents the 75th percentile of historical outcomes, suggesting a bullish boundary for the projected move.
- Lower Bound (Dashed Red): Represents the 25th percentile of historical outcomes, suggesting a bearish boundary for the projected move.
- Match Labels: Small labels appearing on the historical price action indicate exactly where the most similar configurations were found in the past.
🔹 Configuration Strategy
Users can toggle various indicators to define what constitutes a "similar" market state. For example, if only "SMA Cross" and "Supertrend" are enabled, the script will look for historical periods where the trend relationship and SMA positioning were identical to the current bar, regardless of RSI or MACD values.
🔶 DETAILS
The script utilizes a state-encoding methodology to calculate distances between the current market environment and the past. Each enabled indicator is converted into a discrete value (e.g., 1 for bullish, -1 for bearish, 0 for neutral). These values form a vector for the current bar.
The algorithm then scans through the "Historical Lookback" period to find the "Top K" neighbors—the points in history where the vector distance to the current state is minimized. To ensure variety in the forecast, the script includes logic to prevent overlapping matches, ensuring that the selected historical points are distinct events.
Once the matches are identified, the script calculates the percentage returns for the specified "Forecast Horizon (N)" and projects those returns onto the current price to generate the visual forecast.
🔶 SETTINGS
🔹 Parameters
- Top K Neighbors: The number of similar historical configurations to include in the forecast calculation.
- Forecast Horizon (N): How many bars into the future the forecast should extend.
- Historical Lookback: The maximum number of historical bars the script will search through to find matches.
🔹 Indicator Configuration
- RSI/SMA/Supertrend/MACD/ADX/etc.: Toggle switches to include or exclude specific technical conditions from the similarity search.
- RSI: Looks for similar overbought (>70) or oversold (<30) states.
- SMA Cross: Looks for similar Fast/Slow SMA relationships.
- Supertrend: Matches the current direction of the Supertrend.
- MACD: Matches the relationship between the MACD Line and Signal Line.
- RSI: Looks for similar overbought (>70) or oversold (<30) states.
🔹 Visibility & Style
- Show Individual Match Paths: When enabled, draws the actual historical price paths from the match points directly on the current chart for visual comparison.
- Median/Upper/Lower Colors: Customizes the colors of the forecast lines and the shaded confidence intervals.
- Dashboard: Toggles the information panel showing the number of matches found and forecast confidence.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.