Quarterly EPS shown as a Line Graph

danpadcas

New member
Hi all.

I've been looking for a nice way of plotting %EPS increasing/decreasing qtr over qtr on ToS but I did not find anything appealing. I've come across this website and I reckon this is the most accurate indicator I found.

https://playthetrade.com/tradingview/technical-indicators/quarterly-eps-shown-as-a-line-graph/

52FI4Z7.png


What's on the screenshot is a line of graph that follows the EPS results qtr over qtr. The red and green dots represent whether the results were up or down from the previous report. What I'd like to know is if there is a way to calculate the % difference between EPS so we can see at a glance how much has increase or decrease in %.

I follow CANSLIM criteria so that's why I'm requesting it

For those interested in this indicator here is the link;

https://tos.mx/gzJMkvw

And here the Thinkscript Code;

Code:
# EPS line graph
#
# Written by:  @JohnMuchow http://twitter.com/JohnMuchow
# Website:     PlayTheTrade.com
#
# v1.0

declare lower;

input showEPSBubble = yes;

def e = GetActualEarnings();
def earnings = CompoundValue(1, if IsNaN(e) then earnings[1] else e, e);

# Plot the earnings as a line
plot earningsLine = GetActualEarnings();

# Given earnings are not relevant for each bar, approximate line from bar to bar
earningsLine.EnableApproximation();

# Change as you like
earningsLine.SetPaintingStrategy(PaintingStrategy.POINTS);
earningsLine.SetDefaultColor(CreateColor(90, 122, 176));
earningsLine.hideTitle();

# Plot green/red dot indicating earnings up/down
plot earningsUpDownIndicator = GetActualEarnings();
earningsUpDownIndicator.SetPaintingStrategy(PaintingStrategy.SQUARES);
earningsUpDownIndicator.AssignValueColor(if earnings > earnings[1] then (CreateColor(120, 184, 86)) else CreateColor(164, 36, 22));
earningsUpDownIndicator.SetLineWeight(4);
earningsUpDownIndicator.hideTitle();

# Optional EPS bubble
AddChartBubble(showEPSBubble, earningsUpDownIndicator, earnings, Color.GRAY);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hi folks!
As a start, this is a good earnings line. I pushed it up to the main chart and it could use your help.
Can this be programed to show % change on the left side and keep it equal between charts so that a 20% increase in earnings will look the same from chart to chart, even though the price scale varies widely?
Thank you. I hope all is well with the team!
 
Here is a improved version read notes for my add-ons. Enjoy

thinkorswim_KOsRDqyGu7.png

Code:
#====================================================================================================================
# EPS LINE GRAPH
#--------------------------------------------------------------------------------------------------------------------
# Original concept by: @JohnMuchow
# Refined / expanded version
# By: Richard Campbell / AKA Tricky Rick
#
# WHAT THIS STUDY DOES
# - Plots actual EPS reports in a lower study
# - Marks each EPS event with a color-coded square
# - Optionally adds arrows, bubbles, or both
# - Optionally colors main-chart price bars on EPS events
# - Displays current EPS, prior EPS, dollar delta, and percent delta in labels
#
# COLOR LOGIC
# - Green = current EPS improved vs prior EPS
# - Red   = current EPS declined vs prior EPS
# - Gray  = flat or no valid prior comparison
#====================================================================================================================

declare lower;

#====================================================================================================================
# INPUTS
#====================================================================================================================
input epsDisplay = {Arrows, Bubbles, default "Arrows & Bubbles"};
input showZeroLine = yes;
input showEPSLabel = yes;
input bubbleOffset = 0.10;
input arrowOffset = 0.10;
input colorEpsOnPriceBars = no;

#====================================================================================================================
# GLOBAL COLORS
#====================================================================================================================
# Lower-study colors
DefineGlobalColor("EPSLine",  CreateColor(90, 122, 176));
DefineGlobalColor("EPSUp",    CreateColor(50, 205, 50));
DefineGlobalColor("EPSDown",  CreateColor(220, 20, 60));
DefineGlobalColor("EPSFlat",  Color.GRAY);
DefineGlobalColor("ZeroLine", CreateColor(80, 80, 80));

# Main-chart candle reference colors
DefineGlobalColor("EPSPriceUp",   Color.CYAN);
DefineGlobalColor("EPSPriceDown", Color.MAGENTA);
DefineGlobalColor("EPSPriceFlat", Color.GRAY);

# Label spacer color
DefineGlobalColor("LabelSpacer", Color.BLACK);

#====================================================================================================================
# CORE EPS DATA
#====================================================================================================================
# Actual EPS only exists on earnings-event bars
def e = GetActualEarnings();
def hasEvent = !IsNaN(e);

# Carry forward the most recent EPS report between event bars
def earnings = CompoundValue(1, if IsNaN(e) then earnings[1] else e, e);

# Previous reported EPS value
def prevEPS = CompoundValue(1,
    if hasEvent then earnings[1] else prevEPS[1],
    Double.NaN
);

# Current event state relative to previous EPS report
def isUp   = hasEvent and !IsNaN(prevEPS) and e > prevEPS;
def isDown = hasEvent and !IsNaN(prevEPS) and e < prevEPS;

# Held trend state used for persistent label coloring between reports
#  1 = improved, -1 = declined, 0 = flat / no valid comparison
def trendState = CompoundValue(1,
    if hasEvent then
        if IsNaN(prevEPS) then 0
        else if e > prevEPS then 1
        else if e < prevEPS then -1
        else 0
    else trendState[1],
    0
);

# EPS dollar change from previous report
def epsDelta =
    if !IsNaN(prevEPS) and !IsNaN(earnings)
    then earnings - prevEPS
    else Double.NaN;

# EPS percent change from previous report
# Uses AbsValue(prevEPS) so percent math remains readable when prior EPS was negative
def epsPctDelta =
    if !IsNaN(prevEPS) and prevEPS != 0 and !IsNaN(earnings)
    then ((earnings - prevEPS) / AbsValue(prevEPS)) * 100
    else Double.NaN;

#====================================================================================================================
# MAIN CHART PRICE-BAR REFERENCE
#====================================================================================================================
# Optional candle-color reference on the main chart for EPS event bars only
#   Cyan    = EPS improved
#   Magenta = EPS declined
#   Gray    = EPS flat / no valid comparison
AssignPriceColor(
    if colorEpsOnPriceBars and hasEvent then
        if isUp then GlobalColor("EPSPriceUp")
        else if isDown then GlobalColor("EPSPriceDown")
        else GlobalColor("EPSPriceFlat")
    else Color.CURRENT
);

#====================================================================================================================
# EPS EVENT SQUARE
#====================================================================================================================
# Primary EPS event marker
# Left title-visible so hover/readout can reference the EPS event value directly
plot EPS = if hasEvent then e else Double.NaN;
EPS.SetPaintingStrategy(PaintingStrategy.SQUARES);
EPS.SetLineWeight(4);
EPS.AssignValueColor(
    if isUp then GlobalColor("EPSUp")
    else if isDown then GlobalColor("EPSDown")
    else GlobalColor("EPSFlat")
);
EPS.HideBubble();

#====================================================================================================================
# OPTIONAL ARROWS
#====================================================================================================================
# Arrow mode:
#   - Up arrow above EPS square when EPS improved
#   - Down arrow below EPS square when EPS declined
#
# Arrows & Bubbles mode:
#   - Same arrow placement as Arrow mode
plot EPSUpArrow =
    if (epsDisplay == epsDisplay.Arrows or epsDisplay == epsDisplay."Arrows & Bubbles") and isUp
    then e + arrowOffset
    else Double.NaN;
EPSUpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
EPSUpArrow.SetLineWeight(3);
EPSUpArrow.AssignValueColor(GlobalColor("EPSUp"));
EPSUpArrow.HideBubble();
EPSUpArrow.HideTitle();

plot EPSDownArrow =
    if (epsDisplay == epsDisplay.Arrows or epsDisplay == epsDisplay."Arrows & Bubbles") and isDown
    then e - arrowOffset
    else Double.NaN;
EPSDownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
EPSDownArrow.SetLineWeight(3);
EPSDownArrow.AssignValueColor(GlobalColor("EPSDown"));
EPSDownArrow.HideBubble();
EPSDownArrow.HideTitle();

#====================================================================================================================
# OPTIONAL BUBBLES
#====================================================================================================================
# Bubble mode:
#   - Red/down bubbles are forced below
#   - Green/gray bubbles are placed above
AddChartBubble(
    epsDisplay == epsDisplay.Bubbles and hasEvent,
    if isDown then e - bubbleOffset
    else e + bubbleOffset,
    (if e < 0 then "-$" else "$") + AsText(Round(AbsValue(e), 2)),
    if isUp then GlobalColor("EPSUp")
    else if isDown then GlobalColor("EPSDown")
    else GlobalColor("EPSFlat"),
    if isDown then no else yes
);

# Arrows & Bubbles mode:
#   - Bubble is placed opposite the standard arrow side
#   - EPS up   -> arrow above, bubble below
#   - EPS down -> arrow below, bubble above
#   - EPS flat -> bubble above
AddChartBubble(
    epsDisplay == epsDisplay."Arrows & Bubbles" and hasEvent,
    if isUp then e - bubbleOffset
    else if isDown then e + bubbleOffset
    else e + bubbleOffset,
    (if e < 0 then "-$" else "$") + AsText(Round(AbsValue(e), 2)),
    if isUp then GlobalColor("EPSUp")
    else if isDown then GlobalColor("EPSDown")
    else GlobalColor("EPSFlat"),
    if isUp then no else yes
);

#====================================================================================================================
# EPS LINE
#====================================================================================================================
# Original EPS plot using actual reported EPS values
# Approximation visually connects earnings-event points from report to report
# Title is hidden so hover/readout favors the EPS square plot
plot EPSLine = GetActualEarnings();
EPSLine.EnableApproximation();
EPSLine.SetPaintingStrategy(PaintingStrategy.POINTS);
EPSLine.SetDefaultColor(GlobalColor("EPSLine"));
EPSLine.SetLineWeight(2);
EPSLine.HideBubble();
EPSLine.HideTitle();

#====================================================================================================================
# ZERO LINE
#====================================================================================================================
# Optional zero reference to separate positive vs negative EPS
plot ZeroLine = if showZeroLine then 0 else Double.NaN;
ZeroLine.SetDefaultColor(GlobalColor("ZeroLine"));
ZeroLine.SetLineWeight(1);
ZeroLine.HideBubble();
ZeroLine.HideTitle();

#====================================================================================================================
# LABELS
#====================================================================================================================
# Title
AddLabel(showEPSLabel, "   EPS Line Graph    ", Color.LIGHT_GREEN);

# Spacer
AddLabel(showEPSLabel, " ", GlobalColor("LabelSpacer"));

# Primary state label:
#   - Current EPS
#   - Previous EPS
#   - Colored by current EPS state
AddLabel(showEPSLabel and !IsNaN(earnings),
    "   EPS:  $" + AsText(Round(earnings, 2)) +
    (if !IsNaN(prevEPS)
     then "    Prev:  $" + AsText(Round(prevEPS, 2)) + "   "
     else ""),
    if trendState == 1 then GlobalColor("EPSUp")
    else if trendState == -1 then GlobalColor("EPSDown")
    else GlobalColor("EPSFlat")
);

# Secondary stats label:
#   - Dollar delta
#   - Percent delta
#   - Neutral light-gray presentation
AddLabel(showEPSLabel and !IsNaN(earnings),
    (if !IsNaN(prevEPS)
     then "   Δ:  " + (if epsDelta < 0 then "-$" else "$") + AsText(Round(AbsValue(epsDelta), 2)) +
          "   or   " +
          (if !IsNaN(epsPctDelta)
           then AsText(Round(epsPctDelta, 1)) + " %   "
           else "N/A")
     else ""),
    Color.LIGHT_GRAY
);

# Spacer before optional candle-reference label
AddLabel(showEPSLabel and colorEpsOnPriceBars, " ", GlobalColor("LabelSpacer"));

# Confirms EPS event price-bar coloring is active on the main chart
AddLabel(showEPSLabel and colorEpsOnPriceBars, "  EPS Candle Reference is Active  ", Color.CYAN);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
588 Online
Create Post

Similar threads

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.
Back
Top