Upcoming Earning Dates Indicator for ThinkorSwim as Watchlist?

A

ansheth

New member
2019 Donor
Need help with this script. I get wrong results if earnings are after 30 days. I know I need another if statement but not sure what? Any help will be appreciated

Code:
# Next Earnings Label

def Earnings = AbsValue(GetEventOffset(Events.Earnings, 0));
def NextEarnings = if isNaN(Earnings)
                   then 0
                   else Earnings;
def Month = getMonth();
def year = getYear();
def DOW = getDayOfWeek(getYYYYMMDD());
def today = getDayOfMonth(getYYYYMMDD());
def EarningDay = if NextEarnings + DOW <= 5
                 then NextEarnings + today
                 else if between(NextEarnings + DOW, 5, 10)
                 then NextEarnings + today + 2
                 else if between(NextEarnings + DOW, 10, 15)
                 then NextEarnings + today + 4
         else if NextEarnings + Today > 15
                 then NextEarnings + today + 6
                 else NextEarnings;
AddLabel(1, "Next " + getSymbol() + " earnings " + Month + "/" + EarningDay + "/" + AsPrice(year), color.white);
AddLabel(NextEarnings < 30 and NextEarnings > 0,
        "Earnings in " + NextEarnings +
       " trading days", if NextEarnings <= 4
                then Color.Red
                else Color.White);     
addlabel(1, Nextearnings);
# End Code Earnings Date label
 
markos

markos

Well-known member
VIP
@ansheth Please explain what you mean by wrong result? Please post what it looks like.
The code is fine. If it's over 30 days it is not supposed to show a result because that is how it is coded.

Someone please correct me if I am wrong.
 
horserider

horserider

Well-known member
VIP
@ansheth Please explain what you mean by wrong result? Please post what it looks like.
The code is fine. If it's over 30 days it is not supposed to show a result because that is how it is coded.

Someone please correct me if I am wrong.
AddLabel(NextEarnings < 30 and NextEarnings > 0, Looks like you are correct. Very straightforward. Everyone please read the code before seeking assistance.
 
RobertPayne

RobertPayne

Member
@ansheth

Rather than adding a label to my charts, I created a simple watchlist column to show the next earnings release date. I have it setup so that if earnings were released within the last 5 days it will show the most recent release date; otherwise it shows next earnings release.

Ruby:
# 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
def eDay = GetValue(GetDayOfMonth(GetYYYYMMDD()), z);
def eMonth = GetValue(GetMonth(), z);

AddLabel(yes, (if eMonth  < 10 then "0" else "") + eMonth + " / " +
              (if eDay < 10 then "0" else "") + eDay,
        if z <= 0 then Color.CYAN else Color.CURRENT);

 
markos

markos

Well-known member
VIP
@RobertPayne that's a different way of doing it. Thanks for the alternative for those that like to work with an actual date.
 
A

ansheth

New member
2019 Donor
input length=60;
def xx = -getEventOffset(Events.EARNINGS);
def yy = sum(HasEarnings(type = EarningTime.AFTER_MARKET),length)[-length +1] > 0;
plot x=xx+yy*.5;
x.assignValueColor(if x>10 then color.light_red else if x>0 then color.green else color.dark_gray);
@RobertPayne I have this as a watch list column. It also gives me whether it is before Market or after market. But thank you very much. I was aware that I limited the date to not display if more then 30 days. It was my fault as I did not explain the problem correctly. My bad. I have fixed that problem. Thank you so much for your help. Very much appreciated
 
S

soary

Member
@ansheth I like this indicator because it tells if earnings is before or after market but above you said you fixed the problem and did not post the completed corrected code. Is this the fix and if so how to add it to the original code you posted? I'm not a coder so you need to be explicit, Thanks
 
Last edited by a moderator:
L

luketheduke

New member
Is there a way to scan for stocks with earnings scheduled 10 days out instead of 5? Also is there a way to have the date of the earnings as a category on the scan? By category I mean a column on the scan along side "Last" "% Change" "Volume" "Bid" "Ask"?

The only place I can find the scheduled date of earnings is the earnings tab in analyze, but it's kind of inconvenient to have all the windows open if I could just have it in the scan.


Thanks for your help.
 
L

luketheduke

New member
@RobertPayne Can you tell me where to put this code?

Edit: Nevermind I got it, thanks.
 
Last edited by a moderator:
Thread starter Similar threads Forum Replies Date
BenTen Upcoming Releases Playground 2
BenTen Next Earning Date Indicator for ThinkorSwim Indicators 44
Q Scanner for past dates Questions 0

Similar threads

Top