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.
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。