Dividend Yield

Real-time and historical dividend yield information on your favorite stocks, directly inside of your ThinkOrSwim charts.

32 mins
Beginner-Friendly
youtube-video-thumbnail
Table of Contents
    Add a header to begin generating the table of contents
    Table of Contents
      Add a header to begin generating the table of contents

      Introduction

      In this tutorial, we’ll be building a Dividend Yield Indicator for ThinkOrSwim.

      This indicator will allow you to visualize dividend yields on a daily chart, displaying labels and chart bubbles that help identify dividend payouts and yields over time. You can also adjust the yield calculation type and set a customizable yield threshold.

      For Volatility Box members, I have a special “Pro” version of this indicator available, which also includes a Fair Value Calculation, using the Dividend Discount Model.

      Volatility Box Invite

      We are TOS Indicators.com, home of the Volatility Box.

      The Volatility Box is our secret tool, to help us consistently profit from the market place. We’re a small team, and we spend hours every day, after the market close, doing nothing but studying thousands of data points to keep improving and perfecting the Volatility Box price ranges.

      We have two different Volatility Boxes - a Futures Volatility Box and a Stock Volatility Box.

      Futures Volatility Box - Trade Major Markets With an Edge

      Designed For: Futures, Micro-Futures and Index Market Traders
      Supported Models: Hourly Volatility Box models
      Supported Markets: 10 Major Futures Markets

      The Futures Volatility Box comes with:

      • 5 Volatility Models for each market
      • Support for 10 Futures Markets (/ES, /NQ, /YM, /RTY, /CL, /GC, /SI, /ZB, /HG, /NG)
      • Video Setup Guide
      • Trade Plan
      • Access to all members-only resources, including Squeeze Course

      Learn More About the Futures Volatility Box

      Trade futures and micro futures with a consistent volatility edge

      Stock Volatility Box - Powerful Web Based Volatility Platform

      Designed For: Stock and Options Traders
      Supported Models: Hourly and Daily Volatility Box models
      Supported Markets: 10,000+ Stocks and ETFs (new markets added frequently)

      A Stock Volatility Box membership includes access to: 

      • Live Scanner - A powerful scanner we've built from scratch, to scan 10,000 symbols every 2 seconds for new volatility breaches
      • Dashboard - A quick and easy way to view daily volatility model levels online
      • Short Interest Scanner - Short interest, Squeeze, and EMA data to find short squeezes
      • Squeeze Course - All of our proprietary squeeze tools, including robust backtesters
      • All Members Only Indicators - We don't nickel and dime you. Everything really is included.
      • And much more!

      Learn More About the Stock Volatility Box

      Trade stocks and options with a consistent volatility edge

      Step-by-Step Code Tutorial

      Step 1: Setting up the Indicator

      To begin, let’s declare the indicator’s location on the chart and ensure it only runs on a daily time frame:

      
      declare upper;
      Assert(getAggregationPeriod() == AggregationPeriod.Day, "The Dividend Yield indicator works on a daily time frame chart only.");
      

      The declare upper function places the indicator in the main chart area. We also use the Assert function to restrict the indicator to daily charts, as dividend data is only available on daily aggregation periods.

      Step 2: Define Inputs

      Next, let’s create some customizable inputs. We’ll set up controls for the yield calculation method, threshold, and options to show labels and chart bubbles:

      
      input yieldCalculationType = {default "default", "1-yr lookback"};
      input threshold = 0.04; 
      input labelsOn = yes;
      input chartBubblesOn = yes;
      

      With these inputs, users can select between two calculation methods, set a yield threshold for visual cues, and toggle labels and chart bubbles on or off.

      Step 3: Capture the Dividend Data

      We’ll now use ThinkOrSwim’s GetDividend() function to retrieve the dividend data. We need two versions of this variable to capture dividend values correctly:

      
      def dividend = if IsNaN(GetDividend()) then dividend[1] else GetDividend();
      def dividend2 = if IsNaN(GetDividend()) then 0 else GetDividend();
      

      The first variable, dividend, carries forward the previous dividend amount, while dividend2 is set to zero on non-dividend dates. This setup allows us to calculate the total dividends more accurately.

      Step 4: Calculate Total Dividends

      Let’s calculate the total number of dividends for the past year and set a multiplier based on the number of payouts:

      
      def totalDividends = Sum( if IsNaN(GetDividend()) then 0 else 1, 252); 
      def payoutsMult = if totalDividends >= 12 then 12 else 4;
      

      We use Sum to count the dividend days over a 252-day period, and payoutsMult determines if the company has monthly or quarterly payouts.

      Step 5: Calculate Dividend Yield

      Now, we’ll calculate the dividend yield using a switch case for the calculation type:

      
      def dividendYield;
      switch(yieldCalculationType){
      case "default":
          dividendYield = (dividend * payoutsMult) / close;
      case "1-yr lookback":
          def sumPastYrDividends = Sum(dividend2, 252);
          dividendYield = sumPastYrDividends / close;
      }
      

      The default method multiplies the current dividend by the payouts multiplier, while the 1-yr lookback method calculates the yield based on the sum of the past year’s dividends.

      Step 6: Add Labels

      Let’s add labels to display the total payouts, dividend amount, and dividend yield. We’ll also customize label colors based on whether the yield exceeds our threshold:

      
      AddLabel(labelsOn and totalDividends > 0, "Total Payouts: " + totalDividends, color.white);
      AddLabel(labelsOn and totalDividends > 0, "Dividend: $" + Round(dividend,2) + " | Dividend Yield: " + AsPercent(dividendYield), 
               if dividendYield > threshold then color.light_green else color.yellow);
      AddLabel(labelsOn and totalDividends <= 0, "This company does not pay dividends.", color.light_red);
      

      These labels show only if dividends are available. The yield label will turn green if it’s above the threshold, otherwise it remains yellow.

      Step 7: Add Chart Bubbles

      Finally, we’ll add chart bubbles to display the dividend yield at each dividend date. These bubbles will also respect the threshold-based color coding:

      
      AddChartBubble(chartBubblesOn and getDividend(), close, AsPercent(dividendYield), 
                     if dividendYield > threshold then color.light_green else color.yellow);
      

      The bubbles will only appear on bars with dividends. You can control these bubbles with the chartBubblesOn input.

      Step 8: Test and Refine

      Save and apply your code in ThinkOrSwim. Test the indicator across different stocks and adjust the threshold and yieldCalculationType to see the indicator adapt. Now you’ve built a fully functional Dividend Yield Indicator, tailored to display dividend data and yield analysis right on your TOS charts!

      Conclusion

      This Dividend Yield Indicator provides an insightful view into the dividend payouts of any stock that issues dividends, with visual aids and customization to fit your needs.

      For more advanced users, you could further enhance the indicator with additional customization options or pair it with other indicators for a comprehensive yield analysis.

      Thanks for watching, and good luck trading!

      downloads

      Download the Dividend Yield Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Download Indicator

      Download the Dividend Yield Indicator for ThinkorSwim.

      The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.

      Have your own idea?

      Let us help you turn your trading strategy into a powerful indicator, scan and backtester.