This Pine Script analyzes past stock price movements using RSI (Relative Strength Index) and EMA (Exponential Moving Averages - 20, 50, 200 periods) to identify historical patterns and predict potential future price movements.
Key Features:
Pattern Detection:
Compares the current RSI and EMA distances from the price with historical data.
Searches for up to 3 similar patterns from the past within a lookback period (default: 5000 bars).
Similarity Check:
Uses a similarity threshold to determine close matches.
Measures difference in RSI and EMA values to find past occurrences.
Forecasting Future Moves:
Once similar past patterns are found, the script calculates the average price movement over the next 30 bars based on those past occurrences.
Predicts the potential future price movement using the average of these historical moves.
Table Display:
Shows past match dates (formatted correctly as MM/DD/YY).
Displays the expected price change (%) for RSI and EMA-based matches.
Highlights forecasted price movement for the next 30 bars.
How It Works:
The script scans historical data to find similar RSI and EMA patterns.
If matches are found, it records the next 30-bar price movement for those past occurrences.
It then calculates an average forecasted move based on past behavior.
The results are displayed in a table with historical matches and forecasted price changes.
This helps traders analyze whether the current market condition resembles past trends and estimate potential price direction