- Understanding the Smarter Earnings Indicator
- Setting Up Your ThinkOrSwim Workspace
- Step 1: User Inputs
- Step 2: Defining Global Variables
- Step 3: Calculating Earnings Beats and Misses
- Step 4: Identifying Gap Fills
- Step 5: Calculating Gap N' Go Scenarios
- Step 6: Calculating Expected Moves
- Step 7: Adding Labels and Bubbles
- Conclusion
Build a Smarter Earnings Trading System for Day-of-Earnings Analysis
Discover how to create the comprehensive Smarter Earnings indicator that transforms earnings trading from guesswork into systematic analysis using historical patterns and statistical data.
This advanced tutorial teaches you to build a complete earnings analysis system featuring:
- Gap fill detection and analysis with beat/miss correlation
- Gap-and-go pattern identification with average move calculations
- Historical earnings beat/miss tracking and statistics
- Expected move calculations vs. actual move analysis
- Pre-market and after-market earnings classification
- Visual chart bubbles for pattern identification
- Comprehensive labeling system for quick analysis
- Modular code design for future strategy additions
Perfect for traders who want to eliminate guesswork from earnings trading by creating systematic “if-this-then-that” plans based on historical data. This indicator focuses specifically on day-of-earnings analysis, not pre-earnings speculation.
Understanding the Smarter Earnings Indicator
Earnings season brings a wealth of information about companies’ financial health, and traders often look for patterns or anomalies surrounding these announcements. The Smarter Earnings Indicator aims to answer questions like:
- Did a stock beat or miss its earnings estimates?
- Did the price gap up or down following earnings, and if so, did it fill?
- Did the price move beyond its expected range?
By integrating these elements, you get a robust view of how a stock typically responds during earnings announcements, making it easier to make informed trading decisions.
Setting Up Your ThinkOrSwim Workspace
Before we start scripting, ensure that you’re in the ThinkOrSwim platform. Navigate to Charts > Studies > Edit Studies and select Create to open the thinkScript editor. This is where we’ll enter our code.
Step 1: User Inputs
Let’s begin by setting up the inputs for our indicator. These inputs will allow users to customize which elements they want to see on the chart. For example, they may want to display gap fill labels, gap-and-go labels, or expected move labels based on their specific needs.
input expectedMoveLabels = yes;
input gapFillLabels = yes;
input gapNGoLabels = yes;
These three inputs enable users to toggle various labels on and off. Setting them to yes by default makes them visible unless the user decides to hide them.
Step 2: Defining Global Variables
Global variables form the foundation of our calculations. Here, we identify the earnings day and the timing of earnings (before or after the market). These variables will help us group data and later calculate gaps, fills, and trends.
def earningsDay = HasEarnings();
def beforeMarketEarnings = HasEarnings(EarningTime.BEFORE_MARKET);
def afterMarketEarnings = HasEarnings(EarningTime.AFTER_MARKET);
def groupBME = earningsDay and beforeMarketEarnings;
def groupAME = earningsDay[1] and afterMarketEarnings[1];
def earningsGroup = groupBME or groupAME;
def totalEarnings = TotalSum(earningsDay);
In this block, earningsDay is set to detect whether an earnings report is scheduled. We differentiate between earnings reported before the market opens (beforeMarketEarnings) and those reported after it closes (afterMarketEarnings). We then define groups based on these criteria to create an overarching earningsGroup variable.
Step 3: Calculating Earnings Beats and Misses
To determine whether earnings beat or missed expectations, we’ll compare estimated and actual earnings:
def EstimatedEarnings = if IsNan(getEstimatedEarnings()) then EstimatedEarnings[1] else getEstimatedEarnings();
def ActualEarnings = if IsNan(getActualEarnings()) then ActualEarnings[1] else getActualEarnings();
def earningsBeat = if (earningsGroup) and ActualEarnings > EstimatedEarnings then 1 else 0;
def earningsMiss = if (earningsGroup) and ActualEarnings < EstimatedEarnings then 1 else 0;
Here, we handle missing values with IsNan, which allows us to assign values based on previous data. The resulting earningsBeat and earningsMiss variables allow us to track whether the company met, exceeded, or missed expectations.
Step 4: Identifying Gap Fills
Next, we’ll determine whether price gapped up or down after earnings, and if so, whether it filled:
def gapUp = if earningsGroup and open > high[1] then 1 else 0;
def gapDown = if earningsGroup and open < low[1] then 1 else 0;
def gapUpFilled = if gapUp and low = low[1] then 1 else 0;
def gapUpFilledAndEarningsMiss = gapUpFilled and earningsMiss;
def gapDownFilledAndEarningsBeat = gapDownFilled and earningsBeat;
def totalGapUpFills = TotalSum(gapUpFilled);
def totalGapDownFills = TotalSum(gapDownFilled);
def totalGapFills = totalGapUpFills + totalGapDownFills;
def gapUpDidNotFill = (gapUp and !gapUpFilled);
def gapDownDidNotFill = (gapDown and !gapDownFilled);
def gapDidNotFill = gapUpDidNotFill or gapDownDidNotFill;
This code identifies upward and downward gaps and checks whether they filled. The variable gapUpFilled evaluates to 1 if a gap up filled, while gapUpDidNotFill returns 1 if it didn’t. These elements allow you to track trends and movement patterns post-earnings.
Step 5: Calculating Gap N' Go Scenarios
Sometimes, after gapping, prices continue in the direction of the gap without filling it. This is often called a “Gap N' Go.” The code below identifies bullish and bearish Gap N' Go scenarios:
def gapNGoBullish = if gapUpDidNotFill then 1 else 0;
def gapNGoBearish = if gapDownDidNotFill then 1 else 0;
def totalSumGNG = TotalSum(GapNGoBullish) + TotalSum(GapNGoBearish);
def totalSumGNGBullish = TotalSum(GapNGoBullish);
def totalSumGNGBearish = TotalSum(GapNGoBearish);
These Gap N' Go variables track the total number of instances in which a gap did not fill and instead continued in its original direction. This pattern can indicate momentum-driven price action that traders might leverage.
Step 6: Calculating Expected Moves
The expected move calculation considers implied volatility to forecast potential price range movement. This enables traders to measure whether actual price movement exceeded expectations.
def expectedEarningsMove = if earningsgroup then Sqrt(2) / Sqrt(365) * (2*imp_volatility()[1]) * close[1] else Sqrt(2) / Sqrt(365) * (2*imp_volatility()[1]) * close[1];
def actualEarningsMove = if earningsGroup then AbsValue(close[1]-open) else 0;
def greaterThanExpected = actualEarningsMove > expectedEarningsMove;
def totalGreaterThanExpected = TotalSum(greaterThanExpected);
def totalGreaterThanExpectedPct = totalGreaterThanExpected/totalEarnings * 100;
Using the square root of time formula, we estimate the price's potential movement based on implied volatility. We compare the actual move with the expected range, and if the actual movement exceeds the range, we mark it for reference.
Step 7: Adding Labels and Bubbles
Finally, we add labels and chart bubbles to display the calculated values on the chart. This provides a visual reference to the data generated by the indicator.
AddLabel(gapFillLabels or gapNGoLabels or expectedMoveLabels, "Total # of Earnings: "+totalEarnings, color.white);
AddLabel(gapFillLabels, "Total Gap Fills: "+totalGapFills, color.cyan);
AddLabel(gapNGoLabels, "Total Gap N' Go's: "+totalSumGNG, color.green);
AddLabel(expectedMoveLabels, "# of Actual Greater Than Expected: "+totalGreaterThanExpected, color.yellow);
AddLabel(expectedMoveLabels, "% of Actual Greater Than Expected: "+totalGreaterThanExpectedPct, color.yellow);
AddChartBubble(earningsDay, low, "Earnings", Color.DARK_GREEN, no);
Each label and bubble displays a specific piece of information. You can toggle their visibility based on the inputs defined earlier.
Conclusion
With the Smarter Earnings Indicator, you gain insights into a stock's behavior around earnings announcements. The indicator helps you track earnings beats/misses, identify gaps and fills, and analyze the price action relative to expected moves. By adapting the inputs and settings, you can customize it for your trading style and strategy, whether you want detailed statistics or high-level information.
## Built by TOS Indicators 2019
## Smarter Earnings
## Last Update: 10/17/2019
## Full Tutorial Available Here: https://www.tosindicators.com/indicators/smarter-earnings
### User Inputs
// ... 167 more lines ...Here are some resources that you may find useful: