ThinkorSwim Earnings Date Indicator and Watchlist Column

soary

Member
Hello @Marcos, I forgot to say in my post that I'm not a coder and newbie at learning Ts so I would now how to fix it if I spent a lifetime in the tutorial section and that's why I asked for help. I know how to follow instructions so though I could get more help. Thanks anyway.
 

UnclPutz

New member
Brand new here & enjoying the forums so far. I use the code from Mobius (below) in my watchlist & so far so good. However I would like to modify this to count off the total days (including weekends) until earnings & not just trading days. Any ideas on how to do this? TIA!!!

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);
 

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
@soary Did you ever get this fixed? If not, please post in the questions forum, hopefully you will get a bite.
 

markos

Well-known 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
@ezrollin If you got this to work, would you share in a new thread? Thanks.
 

jngy2k

Member
i've updated the code to work only in DAY chart.
It returns a false value for # of days til earnings
when looking at other time frames.

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();



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 DaysToEarnings = getNextEarningsBarNumber;

DaysToEarnings.Hide();



AddLabel(getAggregationPeriod()==aggregationPeriod.DAY and getNextEarnings > 0, "Next Earnings: (" + getNextEarnings + (if getNextEarnings == 1 then " Day): " else " Days): ") + getNextEarningsMonth + "/" + getNextEarningsDay + "/" + AsPrice(getNextEarningsYear), Color.Pink);

AddLabel(getAggregationPeriod()==aggregationPeriod.DAY and getNextEarnings == 0, "EARNINGS TODAY", Color.Yellow);


Additionally I do need help with something. @BenTen @markos @tomsk

First for a custom column the values are incorrect. Today is 10-4-2020 and earnings for ACCD is 10-14-2020.
That will be in 8 trading days or in TOS 8 Day Bars.
Is it possible to make a column OR scan because I think without the expansion (that is available on chart)
it cannot be done.

edit: nevermind i figured it out
i do still need help with the other post
about turning off the "earnings today" label when expansion is off
#column

def getNextEarnings = AbsValue(GetEventOffset(Events.EARNINGS, 0));
plot DaysToEarnings = getNextEarnings;


F2DwucOh.jpg
 
Last edited:

jngy2k

Member
And secondly
there is a False-positive value when Expansion on the chart is not added.
I use a chart Volume Profile with expansion in order to see volume profile.
When that is turned off the Next Earnings indicator will produce a
False "earnings today" label.
In the example below and above, ACCD has earnings in 10-14-2020 with today 10-4-2020 which correctly gives 8 trading days (bars)
from today. Without expansion it is producing the false positive.
Is there a simple off function for the script when expansion is not detected???

BLTTLpXh.jpg
JM92u07h.jpg
 

markos

Well-known member
VIP
@jngy2k I have not been able to get earnings to work on a chart label. I don't need it there so I gave up trying.
I do use one for my watchlists and it serves my purposes. See if this is of any use on a chart. btw, I haven't seen a work around for not having expansion room, but I haven't looked either. Markos

Code:
#For Watch List Column: This code originaly from Thinkscript Lounge at TOS circa 2017
#I use this one because it tells me xx.0= earns before market & xx.5 = earns after market close.
#Please notice that it counts down starting at 60 days and is adjustable via UI.  Markos at usethinkscript.com

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 yy!=0 then color.LIGHT_RED else color.Yellow);

Have you checked the OneNote Repository in Tutorials? Johnny Quotron has kept practically every days TSL chat in there since beginning of 2018.
 
Last edited:

jngy2k

Member
@markos
Ok the best nextearnings indicator i can come up with.
still can't get it to work without expansion unfortuneately

Code:
#original nextearnings

declare lower;
def bn = BarNumber();
def na = Double.NaN;
def getNextEarnings = absvalue(GetEventOffset(Events.EARNINGS, 0));
def findDay = GetDayOfMonth(GetYYYYMMDD());
def findMonth = GetMonth();
def findYear = GetYear();
#getnextearningsbarnumber is confusing but for setting the mo/d/yr
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);

#different nextearnings with aftermarket is .5 and whole number is before or during market hours
input length = 63;
def xx= -geteventOffset(events.EARNINGS);
def yy = sum(hasEarnings(type = earningTime.AFTER_MARKET),length)[-length +1] >0;
plot DaysToEarnings = xx+yy*.5;

DaysToEarnings.assignvaluecolor( if yy!=0 then color.LIGHT_RED else color.Yellow);

#labels for original nextearnings with different nextearnings data
AddLabel(getAggregationPeriod()==aggregationPeriod.DAY and getNextEarnings > 0, "Earnings: (" + DaysToEarnings + (if getNextEarnings == 1 then " Day) " else " Days) ") + getNextEarningsMonth + "/" + getNextEarningsDay + "/" + AsPrice(getNextEarningsYear), Color.Pink);

#indicators for before or during or after earnings
plot isBefore = HasEarnings(EarningTime.BEFORE_MARKET);
plot isAfter = HasEarnings(EarningTime.AFTER_MARKET);
plot isDuringOrUnspecified = HasEarnings() and !isBefore and !isAfter;

isbefore.setDefaultColor(color.yellow);
isafter.setDefaultColor(color.red);
isduringorunspecified.setDefaultColor(color.orange);

isBefore.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
isAfter.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
isDuringOrUnspecified.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
 

markos

Well-known member
VIP
@markos
Ok the best nextearnings indicator i can come up with.
still can't get it to work without expansion unfortuneately

Code:
#original nextearnings

declare lower;
def bn = BarNumber();
def na = Double.NaN;
def getNextEarnings = absvalue(GetEventOffset(Events.EARNINGS, 0));
def findDay = GetDayOfMonth(GetYYYYMMDD());
def findMonth = GetMonth();
def findYear = GetYear();
#getnextearningsbarnumber is confusing but for setting the mo/d/yr
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);

#different nextearnings with aftermarket is .5 and whole number is before or during market hours
input length = 63;
def xx= -geteventOffset(events.EARNINGS);
def yy = sum(hasEarnings(type = earningTime.AFTER_MARKET),length)[-length +1] >0;
plot DaysToEarnings = xx+yy*.5;

DaysToEarnings.assignvaluecolor( if yy!=0 then color.LIGHT_RED else color.Yellow);

#labels for original nextearnings with different nextearnings data
AddLabel(getAggregationPeriod()==aggregationPeriod.DAY and getNextEarnings > 0, "Earnings: (" + DaysToEarnings + (if getNextEarnings == 1 then " Day) " else " Days) ") + getNextEarningsMonth + "/" + getNextEarningsDay + "/" + AsPrice(getNextEarningsYear), Color.Pink);

#indicators for before or during or after earnings
plot isBefore = HasEarnings(EarningTime.BEFORE_MARKET);
plot isAfter = HasEarnings(EarningTime.AFTER_MARKET);
plot isDuringOrUnspecified = HasEarnings() and !isBefore and !isAfter;

isbefore.setDefaultColor(color.yellow);
isafter.setDefaultColor(color.red);
isduringorunspecified.setDefaultColor(color.orange);

isBefore.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
isAfter.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
isDuringOrUnspecified.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
@jngy2k
When TOS was created, the rumor was that the Russian programmers were told to only work with what's on the chart, hence the need for expansion. Oddly, this doesn't hold true with everything.
 

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.
 

walksonair

New 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);

5rGQGgf.jpg
When I try to implement this in my scanned watchlist, I don't get a correct earnings date. What am I doing wrong? See image below please:

wqGngPk.png
 

shgreenejr

New member
VIP
Man, you know what would be a dope indicator, watchlist column or scan? A scan that told you when a stock had a recent earnings pull back for a few days/weeks, and then had a gap up. Could potentially tell you when the pull back was over
 

XeoNoX

Well-known member
VIP
scan for
Has earnings within past XYZ Days (bars) ago
Set to scan to day aggregation
Code:
#Has earnings within XYZ Days ago
#  By XeoNoX Via usethinkscript.com
def daysago = 1;
def HasER_X_daysago = sum(hasearnings(),daysago) > 0;
plot scan = HasER_X_daysago;
 

gravity2726

Member
VIP
scan for
Has earnings within past XYZ Days (bars) ago
Set to scan to day aggregation
Code:
#Has earnings within XYZ Days ago
#  By XeoNoX Via usethinkscript.com
def daysago = 1;
def HasER_X_daysago = sum(hasearnings(),daysago) > 0;
plot scan = HasER_X_daysago;
Thanks Xeonox...
 

shgreenejr

New member
VIP
scan for
Has earnings within past XYZ Days (bars) ago
Set to scan to day aggregation
Code:
#Has earnings within XYZ Days ago
#  By XeoNoX Via usethinkscript.com
def daysago = 1;
def HasER_X_daysago = sum(hasearnings(),daysago) > 0;
plot scan = HasER_X_daysago;
Thanks!!
 

gravity2726

Member
VIP
scan for
Has earnings within past XYZ Days (bars) ago
Set to scan to day aggregation
Code:
#Has earnings within XYZ Days ago
#  By XeoNoX Via usethinkscript.com
def daysago = 1;
def HasER_X_daysago = sum(hasearnings(),daysago) > 0;
plot scan = HasER_X_daysago;
Hi Xeonox,

I am using this as a scan to backtest, It doesn't work on backtest. As it is taking current date in def daysago=15 ( I used last 15 days). Is there a way It to take the on demand date and calculate the last 15 days from on demand date ( or backtest date). Thank you
 

XeoNoX

Well-known member
VIP
sounds more like a issue with ondemand, call tdameritrade and ask them what they recommend.
 

Similar threads

Top