I have blended an earnings date script from Robert Payne and an AddLabel script from Mobius. It works fine for earnings dates up to five days in the past (as it should via the script) and for earnings dates in the next month (September). But when it goes out to the following months (October +) it makes all of the dates 10/14/2024. It did the same thing before I changed the AddLabel script so the issue appears to be in the earlier lines.
Code:
## watchlist column for earnings release date
## Robert Payne
def PE = GetEventOffset(Events.EARNINGS, -1);
def NE = GetEventOffset(Events.EARNINGS, 0);
def z = if PE <= 5 then PE else NE;
## get the earnings date (original of Payne now # to keep as comment)
#def eDay = GetValue(GetDayOfMonth(GetYYYYMMDD()), z);
#def eMonth = GetValue(GetMonth(), z);
## get the earnings date (from Mobius but tweaked to blend with Payne formula)
def data=GetValue(GetYYYYMMDD(),z);
def year=Round(data/10000,0);
def month=Round((data%10000)/100,0);
def day=(data%100);
AddLabel(1,month+"/"+day+"/"+AsPrice(year),if z<=0 then color.CYAN else color.WHITE);
End Code
Here is the results. I added KR to the Mag7 watchlist so you could see a September earnings date. KR is perfect, NVDA is perfect, AAPL should be 10/31, AMZN should be 10/24, GOOG should be 10/22, META should be 10/30, MSFT should be 10/22, and TSLA should be 10/16. I can't find the error. Can anyone help me? I love the script and it will work somewhat but I would like to know why ToS system pulls the correct next Earnings Date but not my script.
i think column studies, can only look ahead 30 days?
load your code as an upper chart study, set to day, and set expansion to 200
compare to the column study
load AMGN
next earnings is on,
on chart, 11/5
on column, 10/14
add this label to chart study, to rule out conversions and formulas,
addlabel(1, ne);
-46 days away
add that label to column study, to replace original label.
max out at -30
in the column study, try different times.
at 2 days, the number changes to -15 , so still 30 days