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
http://www.smallDogInvestor.com
# 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
-allen

9 comments:

  1. Thank you this is awesome!

    ReplyDelete
  2. Thanks for sharing this. Sincerely appreciate your posts

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

    ReplyDelete
  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

    ReplyDelete
    Replies
    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.
      best.
      -allen

      Delete
  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

    ReplyDelete
  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

    ReplyDelete