OPEN-SOURCE SCRIPT

Indicator Configuration Forecasting [LuxAlgo]

1 502
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

  • 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.


🔹 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.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.