ThinkorSwim Earnings Date Indicator and Watchlist Column

jox51

Member
2019 Donor
For earnings, if you don't want to mess with the chart another alternative is below. Below indicator is watchlist column that lets you know the days till earnings if within 30 days. If more than 30, the watchlist column will just say 30. If under 4 days till earnings, will highlight the number in red.

Code:
# WatchList Days Till Earnings 

# If over 30 days away shows 30 

# Mobius 

def LastEarningsBar = AbsValue(GetEventOffset(Events.Earnings, 0));

def NextEarnings = if isNaN(LastEarningsBar) then 0 else LastEarningsBar;

AddLabel(1, NextEarnings, if NextEarnings <= 4 then Color.Red else Color.Current); 

# End WatchList Code for X Earnings  

https://tos.mx/vHhzS9

This is another watchlist column that shows next earnings date.

https://usethinkscript.com/threads/...or-for-thinkorswim-as-watchlist.926/post-6551
 

Sonima

New member
Hi all, I got only the first label even if less than four days remain to the Earning days. Anyone know why?!
 

tomsk

Well-known member
VIP
Hi all,
I got only the first label even if less than four days remain to the Earning days.
Anyone know why?!

If you read the code, it says it will display the label in RED in there are 4 or less days remaining to earnings, i.e. 4, 3, 2, 1

Code:
AddLabel(1, NextEarnings, if NextEarnings <= 4 then Color.Red else Color.Current);
 

tomsk

Well-known member
VIP
Make sure you have sufficient bars defined in your expansion area. If you do not do this, you won't see the data. Check that you are using DAILY aggregation.

Go to Settings > Time Axis > Expansion area. I set mine to 22 bars to the right
 

Sonima

New member
Many thanks tomsk, appritiate your swift reply.
There should be some error there for me.
This always returns N/A for me!
Code:
AbsValue(GetEventOffset(Events.EARNINGS, 0));

It is strange as it works fine in the watchlist column, but not on the chart. Even in the watchlist, days to earning is always correct, but not Earning date!
 

tomsk

Well-known member
VIP
Be very specific as to where you're seeing the error - scanner, watchlist, chart, strategy.
If you're just using that single line of code in post #24 above, I can GUARANTEE it won't work
Post your entire code, let us know where you're using it, what symbol, what aggregation so that someone will have the details to help you.
@BenTen has always said to be specific and to provide all the relevant info.
Saying things like it doesn't work - has no meaning otherwise
 

Sonima

New member
Hi again!
Entire code is posted at the first post of this topic (and several times after) and thus no need for repetition I guess.
I was specific I believe:
"It works fine in the watchlist column, but not on the chart".
Regardless of the symbol, it won't work on the chart on a daily time frame. I have also extended the chart by 30 bars to the right.
Thanks again.
 

tomsk

Well-known member
VIP
@Sonima Ah! Now we are getting somewhere. I immediately see where the problem is. When this code was released in the ThinkScript Lounge months ago, several people pointed out that that code is FUBAR. Do not use that as it is inaccurate. Let me give you an example. Load the study that was posted in post #1 of this thread. Set your aggregation to DAILY and load up ticker symbol C. Just to be sure I have my expansion space set to 44.

What happens? Notice that that particular study reports that the next C earnings is on 12/33/2019. That is clearly wrong.

@BenTen Please take note and either DELETE or TAG that study as being inconsistent.

As a workaround, I have a study that I obtained from a long standing contributor in the ThinkScript Lounge. That study works much better and is an improved version over the original release that was created 4-5 years ago. It correctly reports that ticker C will report earnings in 25 days, on 1/14/2020.

Here is the code

Code:
# Next Earnings Date
# Paris
# 10.15.2019

# You have to have enough expansion area on your chart available to reach the actual Earnings date, so if you have 0 expansion area, an inconsistent date will be displayed

#HINT: watchlist label that shows days-to-earnings and next earnings date (if next earnings date is available).  Includes a visual alert if "EARNINGS TODAY"

#def allows you to teach ThinkScript new "words" to save time and typing by using your new "words" later in the code
def bn = BarNumber();
def na = Double.NaN;
def getNextEarnings = AbsValue(GetEventOffset(Events.EARNINGS, 0));
def findDay = GetDayOfMonth(GetYYYYMMDD());
def findMonth = GetMonth();
def findYear = GetYear();

#ThinkScript thinks in numbers, including converting dates into numbers and viewing each bar on the chart as a number.  Therefore you can use BarNumber to tell ThinkScript which bar, and use lines in ThinkScript code to 'trick' ThinkScript into displaying that daily bar in date format
def getNextEarningsBarNumber = if !isNaN(getNextEarnings) then bn + getNextEarnings else na;
def NextEarnings = bn == HighestAll(getNextEarningsBarNumber);
def getNextEarningsMonth = HighestAll(if NextEarnings then findMonth else na);
def getNextEarningsDay = HighestAll(if NextEarnings then findDay else na);
def getNextEarningsYear = HighestAll(if NextEarnings then findYear else na);

#plot tells ThinkScript what data you want displayed.  Hide() is used in this case because desired display is the label and not the numberic equivalent of the data
plot DaysToEarnings = getNextEarningsBarNumber;
DaysToEarnings.Hide();

AddLabel(getNextEarnings > 0, "Next Earnings: (" + getNextEarnings + (if getNextEarnings == 1 then " Day): " else " Days): ") + getNextEarningsMonth + "/" + getNextEarningsDay + "/" + AsPrice(getNextEarningsYear), Color.Pink);
AddLabel(getNextEarnings == 0, "  EARNINGS TODAY ", Color.Yellow);
# End Next Earnings Date
 
Last edited:

BenTen

Administrative
Staff member
Staff
VIP
Thank you, @tomsk, for the heads up. I just made some notes regarding this issue in the original thread.
 

Sonima

New member
Hi!
The code you have posted is very similar to this:
Code:
https://usethinkscript.com/threads/earnings-scan.123/#post-724

These scripts work perfect in the watchlist but not on the chart. I redirect you to my first post. As far as TOS return N/A for the Earnings in the below line of the code, then none of such scripts works on charts!

Code:
def Earnings = AbsValue(GetEventOffset(Events.EARNINGS, 0));

Thanks anyway for your time and answer.
 

tomsk

Well-known member
VIP
@Sonima Your post yesterday specified that the script you used worked on the watchlist but not on the charts, Hence I started to look into the problem with the charts.

Please READ post #27, it tells you VERY CLEARLY how to resolve the issue on the charts. Yes I believe the version posted was based on Cindy's scripts from 2015, the difference is that Cindy's was written specifically for the watchlist. The version I posted was modified to work on the charts.

Since you specify you have no problems with your watchlist version, we're DONE. I won't be spending any more time on this issue
 
Last edited:

soary

Member
Hello all, I tried this indicator on the chart and still get the wrong date. I updated the expansion bars to 22 and have it on a daily chart like @tomsk instructed. For example, ticker D for Dominion TOS analyze thab-> earnings shows next earnings date as 2/10/2020 but pink label on the chart says 2/11/2020. I tried several tickers and they all have the wrong date. How do I fix it? Thanks
 

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:

markos

Well-known member
VIP
Hello all, I tried this indicator on the chart and still get the wrong date. I updated the expansion bars to 22 and have it on a daily chart like @tomsk instructed. For example, ticker D for Dominion TOS analyze thab-> earnings shows next earnings date as 2/10/2020 but pink label on the chart says 2/11/2020. I tried several tickers and they all have the wrong date. How do I fix it? Thanks
If you can't get what @tomsk put here to work for you, spend the weekend with the Universe of Thinkscript in our Tutorials Section. Thanks
 

Orios

New member
If you can't get what @tomsk put here to work for you, spend the weekend with the Universe of Thinkscript in our Tutorials Section. Thanks
hi markos,
im sure this is a frequent question. im only able to use tos mobile from work. is there anyway of translating these codes to mobile? or is it more trial and error?
 

markos

Well-known member
VIP
hi markos,
im sure this is a frequent question. im only able to use tos mobile from work. is there anyway of translating these codes to mobile? or is it more trial and error?
@Orios Hi, i also spend most of my time on .mobile. I wrote a post in the Tutorial section for this situation. It's mostly trial and error other than what's written in there. Good luck.
 

ezrollin

Member
VIP
Hey, just an observation. I was told we cant use labels on mobile. May have found a tricky workaround. You can set alerts and that will show our labels. Trying to do Market Sentiment/Adv Decliners. Very tricky though
 

Similar threads

Top