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.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
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.
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
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.
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。