Percent yield label

DivNDrip

New member
Hi Can anyone help me to add percent yield label to my charts, I saw one of the TD education coaches use and as DGI it would help me a lot. Thanks a lot. I found this searching but something is wrong and not getting the right data

def DivPayout = if IsNaN(DividendPayout())
then DivPayout[1]
else DividendPayout();
AddLabel(show_labels and DivPayout, "Dividend Payout = " + round(DivPayout,2) + "%", GlobalColor("neutral"));

def DivPerShare = if IsNaN(DividendsPerShareTTM())
then DivPerShare[1]
else DividendsPerShareTTM();
AddLabel(show_labels and DivPerShare, "Dividend Per Share = " + AsDollars(DivPerShare), GlobalColor("neutral"));

def DivYield = if IsNaN(DividendsPerShareTTM())
then DivPerShare[1]
else DividendsPerShareTTM()/Close;
AddLabel(show_labels and DivPerShare, "Dividend Yield = " + AsPercent(DivYield), GlobalColor("neutral"));
 
Solution
@DivNDrip Fundamentals are not my strong point, never found them helpful for my style of trading. So you will have to verify the accuracy - test this and see if it is correct. Not modified in editor, so may have errors.
Code:
# Yield Label
# excerpt from code written by Mobius 

def CurrDivi = if IsNaN(GetDividend())
                    then CurrDivi[1]
                    else GetDividend();
def LastDividend = if CurrDivi != CurrDivi[1]
                    then CurrDivi[1]
                    else LastDividend[1];
def YearlyDiv = if LastDividend == 0
                 then CurrDivi * 4
                 else if LastDividend < CurrDivi
                 then (LastDividend * 3) + CurrDivi
                 else YearlyDiv[1]; 
def yield =...
@DivNDrip Fundamentals are not my strong point, never found them helpful for my style of trading. So you will have to verify the accuracy - test this and see if it is correct. Not modified in editor, so may have errors.
Code:
# Yield Label
# excerpt from code written by Mobius 

def CurrDivi = if IsNaN(GetDividend())
                    then CurrDivi[1]
                    else GetDividend();
def LastDividend = if CurrDivi != CurrDivi[1]
                    then CurrDivi[1]
                    else LastDividend[1];
def YearlyDiv = if LastDividend == 0
                 then CurrDivi * 4
                 else if LastDividend < CurrDivi
                 then (LastDividend * 3) + CurrDivi
                 else YearlyDiv[1]; 
def yield = YearlyDiv / close(period = AggregationPeriod.Day)[1];

AddLabel(1,"  Yield = " + AsPercent(yield), color.white);
 
Solution
I am looking to create a custom watchlist column and calculate dividend yield. I want to calculate it using the Div Amount Field * Frequency (based on Div Frequency Field) / Last Price

If Div Frequency is M (monthly), then the Frequency value would be 12.

I need this because many times the Div Yield field is N/A. Look at BKT for example. Div Per Share is also often N/A, BUT the Div Amount Field always seems to have a value.
 
I gave this a shot but I do not believe it's possible. All three of those - div yield, div freq, and last - are built in functions, not customs. Which means I can't go in and copy the code for it.

I was able to reference the quarterly dividend using the following code:
# ---- Returns Dividend Amount $$ -----
input DivPayoutFrequency = {default Quarterly, Monthly, Yearly};
def DCont = if IsNaN(GetDividend()) then DCont[1] else GetDividend();
def Dividend = if DCont <> 0 then DCont else Double.NaN;
AddLabel(1, DivPayoutFrequency + " Div: " + Dividend, Color.WHITE);

However, you can see on BKT, even though it's showing a dividend amount of .0344 on the div column of the watchlist, it actually returns N/A when trying to reference it on the chart. If you check out another ticker that works in the watchlist, you'll see it matches the div column.

So it doesn't look like it's possible with some of these for whatever reason.
 
I am looking to create a custom watchlist column and calculate dividend yield. I want to calculate it using the Div Amount Field * Frequency (based on Div Frequency Field) / Last Price

If Div Frequency is M (monthly), then the Frequency value would be 12.

I need this because many times the Div Yield field is N/A. Look at BKT for example. Div Per Share is also often N/A, BUT the Div Amount Field always seems to have a value.
I gave this a shot but I do not believe it's possible. All three of those - div yield, div freq, and last - are built in functions, not customs. Which means I can't go in and copy the code for it.

I was able to reference the quarterly dividend using the following code:
# ---- Returns Dividend Amount $$ -----
input DivPayoutFrequency = {default Quarterly, Monthly, Yearly};
def DCont = if IsNaN(GetDividend()) then DCont[1] else GetDividend();
def Dividend = if DCont <> 0 then DCont else Double.NaN;
AddLabel(1, DivPayoutFrequency + " Div: " + Dividend, Color.WHITE);

However, you can see on BKT, even though it's showing a dividend amount of .0344 on the div column of the watchlist, it actually returns N/A when trying to reference it on the chart. If you check out another ticker that works in the watchlist, you'll see it matches the div column.

So it doesn't look like it's possible with some of these for whatever reason.
Some members have had good luck w/ this post:
https://usethinkscript.com/threads/percent-yield-label.7199/#post-69762
 
Last edited:
I'll go ahead and post the whole code I created here. Still could use some more tinkering to potentially add ex div dates, but it shows the current dividend amount and plots the dividend yield over time.

Code:
declare lower;
input DivPayoutFrequency = {default Quarterly, Monthly, Yearly};

# ---- Returns Dividend Amount $$ -----
def DCont = if IsNaN(GetDividend()) then DCont[1] else GetDividend();
def Dividend = if DCont <> 0 then DCont else Double.NaN;
AddLabel(1, DivPayoutFrequency + " Div: " + Dividend, Color.WHITE);

# ---- Calculates Dividend Yield ----
plot DivYield;
switch (DivPayoutFrequency) {
case Quarterly:
    DivYield = ((Dividend * 4) / close);
case Monthly:
    DivYield = ((Dividend * 12) / close);
case Yearly:
    DivYield = ((Dividend * 1) / close);
}

AddLabel(1, "Div Yield: " + RoundDown(DivYield * 100, 2) + "%", Color.WHITE);
 
What is the code to export the dividend amount in dollars as it is declared in the company announcement?
The filter in the stock hacker didn't work as the div. amount in the columns
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
507 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