OPEN-SOURCE SCRIPT
Earnings Day - Price Predictor [DunesIsland]

It's designed to analyze and visualize historical stock price movements on earnings report days, focusing on percentage changes.
Here's a breakdown of what it does, step by step:
Key Inputs and Setup
Processing and Calculations (on the Last Bar)
Overall Averages:
Seasonality (Next Quarter Prediction):
Visual Outputs
Purpose and Usage
This indicator helps traders assess a stock's historical reaction to earnings announcements. The overall averages give a broad sense of typical gains/losses, while the seasonality focuses on quarter-specific trends to "predict" potential movement for the upcoming earnings (based on past same-quarter performance). It's best used on daily charts for stocks with reliable earnings data. Note that quarter inference is calendar-based and may not perfectly match fiscal calendars for all companies—it's an approximation.
Here's a breakdown of what it does, step by step:
Key Inputs and Setup
- User Input: There's a single input for "Lookback Years" (default: 10), which determines how far back in time (approximately) the indicator analyzes earnings data. It uses a rough calculation of milliseconds in that period to filter historical data.
- Data Fetching: It uses TradingView's request.earnings function to pull actual earnings per share (EPS) data for the current ticker. Earnings days are identified where EPS data exists on a bar but not on the previous one (to avoid duplicates).
- Price Change Calculation: For each detected earnings day, it computes the percentage price movement as (close - close[1]) / close[1] * 100, representing the change from the previous close to the current close on that day.
Processing and Calculations (on the Last Bar)
- Lookback Filter: It calculates a cutoff timestamp for the lookback period and processes only earnings events within that window.
Overall Averages:
- Separates positive (≥0%) and negative (<0%) percentage changes.
Seasonality (Next Quarter Prediction):
- Identifies the most recent earnings quarter (latest_q).
- Predicts the "next" quarter (e.g., if latest is Q4, next is Q1;
- Again, separates positive and negative changes, computing their respective averages.
Visual Outputs
- Lookback: How far to fetch the data in years.
- Average Change (Green): Showing the average of all positive changes.
- Average Change (Red): Showing the average of all negative changes.
- Seasonality Change (Green): Showing the average of positive changes for the predicted next quarter.
- Seasonality Change (Red): Showing the average of negative changes for the predicted next quarter.
Purpose and Usage
This indicator helps traders assess a stock's historical reaction to earnings announcements. The overall averages give a broad sense of typical gains/losses, while the seasonality focuses on quarter-specific trends to "predict" potential movement for the upcoming earnings (based on past same-quarter performance). It's best used on daily charts for stocks with reliable earnings data. Note that quarter inference is calendar-based and may not perfectly match fiscal calendars for all companies—it's an approximation.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.