ThinkorSwim Earnings Date Indicator and Watchlist Column

Status
Not open for further replies.

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
Found this indicator created by Mobius while I was browsing the thinkScript Lounge. It adds two labels to your chart. One shows the next earning date for the stock. If the upcoming earning date is within five days, it will also add a bright red warning. It sort of acts as an attention grabber to let you know.

YWi7ai4.png


thinkScript Code

Code:
# Next Earnings Label
# Mobius

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 NextEarnings + DOw > 5
                 then NextEarnings + today + 2
                 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);

Shareable Link

https://tos.mx/FDrNKR

Warning: Some users have pointed out that this indicator and the data it provides may be inconsistent. An alternative script has been posted here.
 

Attachments

  • YWi7ai4.png
    YWi7ai4.png
    88.6 KB · Views: 335
Last edited:
Like this script. But it did not display the date correctly for some ticker. e.g.

CPmG3O5.png
 

Attachments

  • CPmG3O5.png
    CPmG3O5.png
    74.2 KB · Views: 236
Although the creator is unknown...this one marks the chart and the user can add a shaded area for the number of days before and after the date...or none at all...just a line.

Code:
input daysBefore = 5;
input daysAfter = 5;

input showLines = yes;
input paintBackground = yes;

DefineGlobalColor("Before Earnings", Color.GREEN);
DefineGlobalColor("Earnings Release Date", Color.YELLOW);
DefineGlobalColor("After Earnings", Color.CYAN);
DefineGlobalColor("Fill Before", CreateColor(178, 216, 166));
DefineGlobalColor("Fill After", CreateColor(131, 191, 213));

AddVerticalLine(showLines and HasEarnings(), "Earnings!", GlobalColor("Earnings Release Date" ), Curve.FIRM);

def before = Sum(HasEarnings(), daysBefore)[-daysBefore];
def after = Sum(HasEarnings(), daysAfter)[1];

def value1 = HighestAll(high);
def value2 = if paintBackground and before then LowestAll(low) else Double.NaN;
def value3 = if paintBackground and after then LowestAll(low) else Double.NaN;

AddCloud(value1, value2, GlobalColor("Fill Before" ));
AddCloud(value1, value3, GlobalColor("Fill After" ));
 
Thanks ben, i like this scan too. But i would like to know if this scan can be configure to scan out stocks that are reporting earning in the next 30 - 40 days?
 
Anyone else having issues with this script? It doesn`t seem to work because no matter which chart i open, it says "Next Earnings in todays date". I havn`t found one single stock where it says "earnings in x trading days".

What am i missing here?
 
Unfortunately the Mobius script gives the wrong date on what I tried it on, BHC.

Code:
# TS Title = Earnings_and_Dividends_Labels
#revised 11/02/12 to add PE Ratio
#hint:Displays a labels that shows the ESTIMATED days-to-actual-earnings & most recent earnings and dividends \nThe chart should be a '1 YR,1 DAY'chart to get best 'estimated days to earnings' because past time-spans are used. Realize also that there may not be earnings scheduled or the data-feed may be inaccurate.\nIn essence this states the estimated-days-to-earnings since the last phone icon of 'Corporate Actions' shown.\nA minus 1 to 5 days is not unusual and means that earnings are imminent.\nIf "Most Recent Earnings" > -180 is shown, then data is likely not available.

def agg = AggregationPeriod.DAY;
def length = 252;
def barnumb = BarNumber();
input DaysToEarnings = yes;#hint DaysToEarnings: Based on the latest time span between earnings. Turns label off when 'no' replaces 'yes'.
input ShowRecentEarnings = yes; #hint ShowRecentEarnings: Turns label off when 'no' replaces 'yes'
input ShowRecentDividends = yes; #hint ShowRecentDividends: Turns label off when 'no' replaces 'yes'
input ShowRecentPE = yes; #hint ShowRecentPE based on recent quarterly earnings X 4: Turns label off when 'no' replaces 'yes'

def AggPeriod = GetAggregationPeriod();
def AggCond = if GetAggregationPeriod() == 86000400 then 1 else 0;


### show where actual earnings (AE) have occurred ###
rec AE = CompoundValue(1, if IsNaN(GetActualEarnings()) then 0 else AE[1] + 1, 0);
plot ActEarn = AE;
ActEarn.hide();
## count no times of actual earnings shows ####
rec AECount = CompoundValue(1, if HasEarnings() then AECount[1] + 1 else AECount[1], 0);
plot P_AECount = AECount;
P_AECount.hide();
Def HighestAECount = highest(AECount,length);

### count days between previous earnings announcements ##
#Def AECountLast =
### StartBar from last actual earnings #####
rec BarStart = CompoundValue(1, if AECount == Highest(AECount, length) && AE[1] == 1 then  BarNumber() else BarStart[1], 1);
Def Var = HighestAECount -1;
rec BarStart2 = CompoundValue(1, if AECount == 2 && AE[2] == 1 then  BarNumber() else BarStart2[1], 1);
#AddLabel(yes,concat("BarStart = ",BarStart));
#AddLabel(yes,concat("BarStart2 = ",BarStart2));

def BarsToEarnings = (BarStart - BarStart2) -(Barnumber()- BarStart) ;

AddLabel(DaysToEarnings, Concat("Est Days to Earnings = ", Concat(BarsToEarnings, " (Use a '1 YR, 1 DAY' chart)")), Color.WHITE);

#### Most recent Earnings & Dividends ########
rec ActualEarnings = CompoundValue(1, if IsNan(GetActualEarnings()) then ActualEarnings[1] else GetActualEarnings(), GetActualEarnings());
rec Dividends = CompoundValue(1, if IsNan(GetDividend()) then Dividends[1] else GetDividend(), GetDividend());
AddLabel(ShowRecentEarnings, Concat("Most Recent Earnings: ",AsText(ActualEarnings, NumberFormat.TWO_DECIMAL_PLACES )), GetColor(5));
AddLabel(ShowRecentDividends, Concat("Most Recent Dividend: ",AsText(Dividends, NumberFormat.TWO_DECIMAL_PLACES )), GetColor(5));
###### PE calculation ##########
#addLabel(ShowRecentPE,"PE ratio = " +  round ((Close/(ActualEarnings *4)),0));
### calc PE Ratio per the manual ######
rec YearsEarnings = if IsNaN(GetActualEarnings()) then 0 else GetActualEarnings();#Relies on a 1YR,DAY chart
plot EPS_TTM = Sum(YearsEarnings, 252);
AddLabel(ShowRecentPE, Concat("P/E Ratio: ",Round(close / EPS_TTM,0)));
#### EOC #######

### Can't get below label to work ###
#AddLabel(yes, If getAggregationPeriod() == 86000400 then  "The Agg is correct" else "The Agg is incorrect" , if  aggperiod == 86000400 then color.green else color.red);
 
Blame it on a Tos update, just like the one that broke the scanner a year ago. Actually, this label needs the expansion open 50 bars or so to work. It only sees what is on the chart. IMO, you're best off using the selection "show corporate actions" in the settings.
 
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
 
@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.
 
@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.
 
Try This:

Code:
#################
# ER Labels
#################
def daysBefore = 100;
def erInDays = AbsValue(GetEventOffset(Events.EARNINGS, 0));
def before = Sum(HasEarnings(), daysBefore)[-daysBefore];
AddLabel(Yes, IF before THEN "ER: "+erInDays+" days" ELSE "ER: No", IF before THEN Color.RED ELSE Color.GREEN);
 
@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);

5rGQGgf.jpg
 
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
 
@AGD Says "ER:No" no matter what symbol i input. Tried several companies with upcoming earnings.
 
Try expanding the bar spacing on your chart to 30 days and then it should display the correct date.
 
Status
Not open for further replies.

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
295 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top