Skip to content
April 19, 2013 / redman59

Scanning with ThinkorSwim: Stocks That Don’t Have Upcoming Earnings in “X” Amount of Days

Having some free time I opened up my TOS Desktop software to try and solve a problem I have when scanning for stocks.  I hate when I want to get long/short a stock but find out that it has earnings within the next two days or any other number in where I am looking to hold for a longer period of time.  One example can be $AAPL.  I want to put on bull put spreads but do not like the fact that it has earnings April 23rd.  This can be true for many stocks when you run a scan and find stocks that fit your criteria but they have earnings coming up, personally I just toss those aside unless it is an earnings specific strategy.  Now I wanted to try and get a scan that can cast those aside as to not crowd the scan or where I don’t have to pre-filter the scan by going to other websites.  I looked on the web but could not find a solution for this so I tried to figure one out.

Going to the Scan Tab I opened up TOS’s source code for Earnings.  The problem is that this only searches for stocks with upcoming earnings within the selected amount of days (default is 10)  but DOES NOT look for those that already had or does not have earnings within a “X” amount of days.  I believe I was able to use their code and supplement some stuff and have figured out a way to search for stocks that have no upcoming earnings with the user able to select the amount of days.  I will try to break this down by the numbers:

1) TOS users can start by opening up their Desktop App and then going to the Scan Tab.

2) Then go to the “Add Study Filter” box to the right and click on it.  This adds and defaults to the “ADX Crossover” box which is added to the bottom of your filter:

earnings

3) Click on the “ADX Crossover” box and scroll down to “Corporate Actions and then over to “Earnings” and the following should be displayed:

earnings_a

4) Next click on that pencil to the right of the “D” and to the left of the “Red X”.  This opens up your script to where you can edit it with the “thinkscript Editor” Tab (as shown below):

earnings_b

4) Highlight the entire text and delete it.  Then paste the following in bold red text :

#Wizard text: Has an earnings annoucement
#Wizard input: Choice
#Wizard text: in the next
#Wizard input: length
#Wizard text: bars

Input length = 20;

input Choice = {default “Any time”, “Before the Market”, “After the Market”};
def earnings = hasearnings();

def scan;

switch (Choice){
case “Any time”:
scan = sum(hasearnings(),length)[-length +1] > 0;
case “Before the Market”:
scan = sum(HasEarnings(type = EarningTime.BEFORE_MARKET),length)[-length +1] > 0;
case “After the Market”:
scan = sum(HasEarnings(type = EarningTime.AFTER_MARKET),length)[-length +1] > 0;
} ;

def x = if(scan,1,0);

plot NoUpcomingEarnings = x == 0;

5) Hit “OK” and then that should work.

I have this set at 20.  But you can easily edit it by going to Line #7 at the “Input length” and change that number to anything you wish.  Keep in mind it looks for stocks that DOES NOT have earnings in those next amount of days, in this case does not have earnings in the next 20 days.  You can then add other filters that fit your personal liking such as price higher than or volume average greater than to further filter it down.

I am not a programmer or coder but just make my own scans as best I can and puzzle stuff together to achieve my goal.  I could not find anything else on the internet but if you have a better way just let me know.  I just wanted to share this with traders that had the same kind of annoyance that I experienced with finding stocks that fit scan criteria only to find they have earnings soon.  Hope this helps.

11 Comments

Leave a Comment
  1. Steve / Jul 5 2013 11:29 am

    Randy,
    Thanks for the post on how to add the TOS earnings date filter for “X” days in future. This was exactly what I have been looking for!. I found your blog from a google search on this subject.

    For what it is worth to you, I wanted to offer a comment on a web site I have found really helpful and interesting. Since you are a TOS user and trade options, you may already know the site but if not, check out the information provided at http://www.TastyTrade.com.

    It is great stuff from Tom Sosnoff (co-founder of ThinkorSwim). It has really helped my options trading.

    Thanks Again,
    Steve
    Minneapolis, MN

    • redman59 / Sep 23 2013 8:49 am

      Thanks for the comment Steve and glad it helped. Yes TastyTrade is the program for traders, so much education there too.

  2. Lynn / Sep 20 2013 6:14 pm

    This is exactly what I was trying to figure out. Thanks so much for sharing it.

    • redman59 / Sep 23 2013 8:50 am

      Thanks for reading Lynn and I’m glad it helped.

  3. Charles / Oct 17 2013 6:18 am

    Thanks for your code it saved me a lot of time.

    I cleaned it up a bit see below:

    #Wizard text: Has no earnings annoucement in the next days

    Input days = 20;

    def earnings = hasearnings();

    def scan = sum(hasearnings(),days)[-days +1] > 0;

    def NoEarnings = if(scan,1,0);

    plot NoUpcomingEarnings = NoEarnings == 0;

    • redman59 / Oct 17 2013 8:06 am

      Thanks Charles for cleaning that up for easier reading, glad it saved you some time.

  4. Franco / Jan 15 2014 11:32 am

    It is a super useful tool
    Thanks!! 🙂

  5. Ravi Vulli / Jan 18 2014 1:54 pm

    Thank you so much, this is exactly I am looking for. It saved me lot of time.

  6. Darron / Feb 23 2015 10:10 am

    Thank you! This script will save me a lot of time.

  7. charlespleasant / May 1 2018 11:43 am

    Do you have a script that would scan for all stocks except Pharma and Helathcare

  8. sinom / Jul 26 2018 7:20 pm

    Hi, many thanks for the script.
    I have a question. How can I check if MACD is bullish with a script?

Leave a comment