Historical Earnings Trend Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
This indicator will display several earnings trend that can be beneficial for traders who use historical earnings data for their investment decision. Another great share by @KRose_TDA on Twitter.
  • Red Squares = Earnings Lower
  • Green Square = Earnings Higher
  • Red Arrow = Earnings below estimates
  • Green Arrow = Earnings above estimates
  • Point of Arrow = Earnings estimates
4LWsbbT.png


thinkScript Code

Code:
#Follow @KRose_TDA on twitter for free updates posted for this and other scripts
#Earnings trend study is used as part of the generating income with dividend stocks webcast presented Monday nights @ 7PM ET   https://events.thinkorswim.com/#/webcast
# I build custom studies like earnings trend as part of my Thursday night thinkscript webinar @ 5:30PM ET
#     https://events.thinkorswim.com/#/webcast
#This study creates a line chart tracking the trend of a stock's quarterly EPS values(it doesn't work for ETFs).A red square appears when Earnings Per Share(EPS)is lower than the prior quarter's EPS, and a dark green square appears when EPS is higher than the previous quarter's EPS. The arrows represent a comparison of an analyst's estimated EPS for that quarter versus the actual EPS. If the arrow is colored Green, the company's actual EPS was greater than the analyst estimates. If the actual EPS was less than the analyst estimates, the arrow will be Red. The point of the arrow equals analyst estimate value.

declare lower;
declare Hide_on_intraday;

def EPS = if !isNaN(GetActualEarnings()) then GetActualEarnings() else EPS[1];

plot EPS_line_chart = GetActualEarnings();
EPS_line_chart.EnableApproximation();
EPS_line_chart.SetDefaultColor(color.black);

plot earnings_date = GetActualEarnings();
earnings_date.SetPaintingStrategy(PaintingStrategy.squares);

earnings_date.AssignValueColor(if EPS > EPS[1] then color.dark_green else color.red);
earnings_date.SetLineWeight(5);

plot EstEarning = GetEstimatedEarnings();
EstEarning.SetPaintingStrategy(PaintingStrategy.arrow_up );

EstEarning.AssignValueColor (if EstEarning < EPS then color.DARK_GREEN else color.DARK_RED);
EstEarning.SetLineWeight(5);

# end code

Shareable Link

https://tos.mx/gt605c
 

Orios

New member
side bar. can someone help add a custom filter in a column that shows when an earnings date is for a company. from work im only able to use mobile but havent found a filter for earnings dates
 

soary

Member
NICE! This is very useful.
Good idea Orios but not just historical price performance post earnings but also a certain % move up/down

TOS has something similar but without %
TOS ->analyze tab->earnings shows next earnings date on top->volatility implied & historical, ATM straddle move, EPS comparison of actual vs wall street in trend lines
 
Last edited:

Orios

New member
NICE! This is very useful.
Good idea Orios but not just historical price performance post earnings but also a certain % move up/down
You can figure that out using options usually the stays in the expected range. A rough estimate is taking the 15 Delta put and call adding them together. Then from current price plus or minus. I have an Excel sheet that does it with the actual calculation but yeah as long as you know standard deviation based on options it tends to stay in that range 68.2% of the time. For earnings the hardest part is knowing probable direction especially if you want to flip money fast. Like right now I could do just 13 Delta iron condors roughly a month out and still win roughly 70 to 80% of the time. But if I knew the usual direction poster earnings I skew bets towards usual outcomes and have the ability to free up capital sooner
 

soary

Member
You can figure that out using options usually the stays in the expected range. A rough estimate is taking the 15 Delta put and call adding them together. Then from current price plus or minus. I have an Excel sheet that does it with the actual calculation but yeah as long as you know standard deviation based on options it tends to stay in that range 68.2% of the time. For earnings the hardest part is knowing probable direction especially if you want to flip money fast. Like right now I could do just 13 Delta iron condors roughly a month out and still win roughly 70 to 80% of the time. But if I knew the usual direction poster earnings I skew bets towards usual outcomes and have the ability to free up capital sooner
I like using Excell what is the formula? I;m guessing you're talking about expected move.
 

J007RMC

Well-known member
2019 Donor
This is an upper chart earnings, estimated, actual, percent gain/loss indicator

Code:
def price = close;
def estimate = GetEstimatedEarnings();
def actual = GetActualearnings();
def get_price = if estimate and actual then price else get_price[1];
def gain = (actual – estimate);
AddChartBubble(estimate,close, “Est: ” + estimate + “\nAct: ” + actual + (if gain <= 0 then "\nLoss: " else “\nGain: ”) + gain, if actual <= estimate then CreateColor(247, 25, 91) else CreateColor(25, 202, 247));
 
Last edited by a moderator:

beh0211

New member
Inspired by this post, I am creating a similar indicator but it show EPS growth comparing to the same quarter last year.

It may not looks good but it is working :)
Code:
#Only works in weekly chart

declare lower;

def EPS = if !isNaN(GetActualEarnings()) then GetActualEarnings() else EPS[1];

def EPSGrowthYoY = if !isNaN(GetActualEarnings()) then round(100*(EPS - EPS[52])/AbsValue(EPS[52]), numberOfDigits = 0) else EPSGrowthYoY[1];

plot pEPSGrowthYoY = EPSGrowthYoY;
pEPSGrowthYoY.SetDefaultColor(color.blue);

plot pZero = 0;
pZero.setDefaultColor(Color.dARK_GRAY);
pzero.setLineWeight(3);

AddLabel(yes, if EPSGrowthYoY!=0 then "EPSGrowthYoY% = " + EPSGrowthYoY+"%" else "EPSGrowthYoY% = " + EPSGrowthYoY + "%", color = Color.Blue);

# end code
 
Last edited:

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
@ReyHak Try this thread https://usethinkscript.com/threads/thinkorswim-indicators-for-basic-fundamental-analysis.866/

Or this one:

Code:
#
# Copyright 2019 Scott J. Johnson (https://scottjjohnson.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# EarningsPerShare
#
# Displays the company's earnings per share over the time period. If overlaying
# this study on a price graph, right click the line and select "Use left axis"
# to adjust the scale.
#
declare upper;

plot Data = getActualEarnings();
Data.SetPaintingStrategy(PaintingStrategy.LINE);
Data.SetLineWeight(2);
Data.SetDefaultColor(Color.LIGHT_ORANGE);
Data.EnableApproximation();
 

petech

Member
I combined the scripts from the first post and the script from another post in this same thread, and then I made some tweaks. How do I add to the bubble to calculate the percentage change in EPS from the prior quarter? I am aware of the syntax of "FiscalPeriod.QUARTER" but I don't now how to use it. I don't really know how to code either. I edited the script by doing a lot of guessing and googling.

CDGEcLv.jpg


Code:
#Follow @KRose_TDA on twitter for free updates posted for this and other scripts
#Earnings trend study is used as part of the generating income with dividend stocks webcast presented Monday nights @ 7PM ET   https://events.thinkorswim.com/#/webcast
# I build custom studies like earnings trend as part of my Thursday night thinkscript webinar @ 5:30PM ET
#     https://events.thinkorswim.com/#/webcast
#This study creates a line chart tracking the trend of a stock's quarterly EPS values(it doesn't work for ETFs).A red square appears when Earnings Per Share(EPS)is lower than the prior quarter's EPS, and a dark green square appears when EPS is higher than the previous quarter's EPS. The arrows represent a comparison of an analyst's estimated EPS for that quarter versus the actual EPS. If the arrow is colored Green, the company's actual EPS was greater than the analyst estimates. If the actual EPS was less than the analyst estimates, the arrow will be Red. The point of the arrow equals analyst estimate value.

declare lower;
declare Hide_on_intraday;

def EPS = if !isNaN(GetActualEarnings()) then GetActualEarnings() else EPS[1];

plot EPS_line_chart = GetActualEarnings();
EPS_line_chart.EnableApproximation();
EPS_line_chart.SetDefaultColor(color.orange);

plot earnings_date = GetActualEarnings();
earnings_date.SetPaintingStrategy(PaintingStrategy.squares);

earnings_date.AssignValueColor(if EPS > EPS[1] then color.dark_green else color.red);
earnings_date.SetLineWeight(5);

plot EstEarning = GetEstimatedEarnings();
EstEarning.SetPaintingStrategy(PaintingStrategy.arrow_up );

EstEarning.AssignValueColor (if EstEarning < EPS then color.DARK_GREEN else color.DARK_RED);
EstEarning.SetLineWeight(5);


### This part added by coping and pasting someone else's script
DefineGlobalColor(“lime”, Color.lime);
def price = close;
def estimate = GetEstimatedEarnings();
def actual = GetActualearnings();
def get_price = if estimate and actual then price else get_price[1];
def gain = (actual – estimate);
AddChartBubble(actual,actual, “EPS: ” + actual, GlobalColor(“lime”));
# end code
 

mbrennan5

New member
Here's what I've been using to scan for 0-4 consecutive quarters increasing EPS:
Code:
#Increasing Earnings Scan #v2.28.14.1
#Scan for earnings > previous quarter earnings

input times_up = 2;
 def gae = GetActualEarnings();
rec ern = if(!isNaN(gae), gae, ern[1]);

#if there are never any earnings this will always = Double.NaN
#Now to determine if earnings are increasing enough times in a row we need to count every time they increase. If earnings are < prior quarter, we'll reset the count to 0.
#CompoundValue is used to make sure the count initializes with a number: 0 in this case. If it starts with Double.NaN, it may not work.
#start this on the first bar: (CompoundValue(1,
#if earnings are reported: if(!isNaN(gae),
#then if earnings are greater than the prior earnings value: if(ern > ern[1],
#count it by adding 1 to the previous count: ern_up[1] + 1,
#else set the count to 0: 0),
#else (if earnings aren't reported) keep the previous count value: ern_up[1]),
#intialize the value of the variable to 0: 0);

rec ern_up = CompoundValue(1, if(!isNaN(gae), if(ern > ern[1], ern_up[1] + 1, 0), ern_up[1]), 0);
plot x =  ern_up >= times_up ;
 
Last edited by a moderator:

DLCjr

New member
Can someone modify this script to include a label that gives you the avg percentage miss/beat of all earnings shown in your chart? i.e. (total gains + losses / number of reports) * 100. I tried and failed.
 

jaricarr

New member
I combined the scripts from the first post and the script from another post in this same thread, and then I made some tweaks. How do I add to the bubble to calculate the percentage change in EPS from the prior quarter? I am aware of the syntax of "FiscalPeriod.QUARTER" but I don't now how to use it. I don't really know how to code either. I edited the script by doing a lot of guessing and googling.

CDGEcLv.jpg


Code:
#Follow @KRose_TDA on twitter for free updates posted for this and other scripts
#Earnings trend study is used as part of the generating income with dividend stocks webcast presented Monday nights @ 7PM ET   https://events.thinkorswim.com/#/webcast
# I build custom studies like earnings trend as part of my Thursday night thinkscript webinar @ 5:30PM ET
#     https://events.thinkorswim.com/#/webcast
#This study creates a line chart tracking the trend of a stock's quarterly EPS values(it doesn't work for ETFs).A red square appears when Earnings Per Share(EPS)is lower than the prior quarter's EPS, and a dark green square appears when EPS is higher than the previous quarter's EPS. The arrows represent a comparison of an analyst's estimated EPS for that quarter versus the actual EPS. If the arrow is colored Green, the company's actual EPS was greater than the analyst estimates. If the actual EPS was less than the analyst estimates, the arrow will be Red. The point of the arrow equals analyst estimate value.

declare lower;
declare Hide_on_intraday;

def EPS = if !isNaN(GetActualEarnings()) then GetActualEarnings() else EPS[1];

plot EPS_line_chart = GetActualEarnings();
EPS_line_chart.EnableApproximation();
EPS_line_chart.SetDefaultColor(color.orange);

plot earnings_date = GetActualEarnings();
earnings_date.SetPaintingStrategy(PaintingStrategy.squares);

earnings_date.AssignValueColor(if EPS > EPS[1] then color.dark_green else color.red);
earnings_date.SetLineWeight(5);

plot EstEarning = GetEstimatedEarnings();
EstEarning.SetPaintingStrategy(PaintingStrategy.arrow_up );

EstEarning.AssignValueColor (if EstEarning < EPS then color.DARK_GREEN else color.DARK_RED);
EstEarning.SetLineWeight(5);


### This part added by coping and pasting someone else's script
DefineGlobalColor(“lime”, Color.lime);
def price = close;
def estimate = GetEstimatedEarnings();
def actual = GetActualearnings();
def get_price = if estimate and actual then price else get_price[1];
def gain = (actual – estimate);
AddChartBubble(actual,actual, “EPS: ” + actual, GlobalColor(“lime”));
# end code

Hello and thanks so much for this code. Is it possible to add historical dividends to this code ? Perhaps plotting circles
 

Jazflyer

New member
I am looking to see only the yearly EPS. Is there a function that I can use in the code to plot that? I tried EarningsPerShare TTM but that plotted too many data points. I am trying to only connect total yearly earings (one point per year).Thanks
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
I am looking to see only the yearly EPS. Is there a function that I can use in the code to plot that? I tried EarningsPerShare TTM but that plotted too many data points. I am trying to only connect total yearly earings (one point per year).Thanks
If you use a yearly aggregation then by default you get one point per year
 

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top