Sunday, October 6, 2013

thinkscript included: customize your watchlist to sort in the order of upcoming earnings

with the pace of enhancements to the tos platform i guess i shouldn't be too surprised that i stumble on things i didn't know were there. however, i've long been frustrated by the fact that there wasn't a natural mechanism to sort a watch-list in the order of upcoming earnings. so, today i set about building a custom column to show something like days to earnings when i stumbled on the function, geteventoffset(). geteventoffset() returns the number of bars into the future of a corporate event. this was an easy button for creating the custom column i call bte (bars-til-earnings.) 

Equities with weekly options sorted in order of upcoming earnings
here's the thinkscript for this column:

# sdi_tde: trading days til earnings
#hint: displays the trading days til earnings. after-market earnings add 0.5 to the count. this code is meant to be pasted into a custom watchlist column. rev: 1.2
# author: allen everhart
# date: 08oct2013
# rev 1.2: 8mar2014 color code the after-market earnings.
# rev 1.1: 22oct2013 add 0.5 if earnings are after-market.
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place.

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

the only little gotcha is the minus sign. geteventoffset() returns negative numbers because in thinkscript a negative offset is a reference in the future time direction. 

here's how to get this custom column on your watch-list:

  1. right click on any column heading in your watch-list and select customize at the top of the pop-up list.
  2. scroll the available items list of the watchlist dialogue and click on the left-hand icon of one of the custom columns that you haven't already used.
  3. replace the default column name with bte in the column name text entry box of the custom quote formula dialogue.
  4. click on the thinkscript editor tab and replace the default formula with the thinkscript: -GetEventOffset( eventType = Events.EARNINGS)
  5. click ok
  6. click add item(s)>> button
  7. click move up or move down buttons to position the bte column to your preference.
  8. click ok

happy trading to you


  1. Thank you this is awesome!

  2. Thanks for sharing this. Sincerely appreciate your posts

  3. That's great. Exactly what i looked for. Thanks for your effort.

  4. Hey, i tried installing this today. how come some are not whole numbers but have.5s like 30.5 or 26.5 for example and all those are in RED and everything else in grey? Thanks

    1. hi, the .5 indicates that the earnings occur after the market closes. i color those red just to give a sense of grouping in the watchlist. one of the frustrations i have with tos calendar is that all earnings are presented as occuring on a particular date, morning or evening. however, for vol-crush strategies you'll want to trade the morning earnings on the day before and evening earnings on the day of the earnings.

  5. Hey, i tried installing this today. how come some are not whole numbers but have.5s like 30.5 or 26.5 for example and all those are in RED and everything else in grey? Thanks

  6. Handy script but wish it worked for options, is there a way to make it use the GetUnderlyingSymbol so it would show up on an options scan or watchlist. Thanks

  7. It worked great. How can I change it from 'Trading' days to earnings to 'Total' days to earnings to include weekends, holidays, etc


  8. Great article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information.. petsafe wireless dog fence

  9. Hello. A great product !!!! Can I change this code so that it shows how many days left before dividends (eh-div)? Thank you.

  10. Thanks a lot for the great job.
    One thing happened to my TOS is there are lots of tickers never show up the earning date,

    It shows " exceeding the limits "
    Is there a way to deal with it?


  11. Your website is really cool and this is a great inspiring article. Thank you so much. view it now

  12. Is there a simple way to do scans on just a watchlist rather than all stocks?

  13. I'm happy I found this blog.
    Read here at petcareio

  14. Thank you Allen, you have no idea how much it helps me. I just discovered you can use it in the Scan tab in addition to use it in the Watchlist. Now I can scan my stocks and sort it by earning date (bte).

    Thanks again, you are awesome!


Note: Only a member of this blog may post a comment.