Percent yield label

DivNDrip

New member
VIP
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 =...

Pensar

Well-known member
VIP
@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

jtpdev

New member
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.
 

Internet Name

New member
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.
 

MerryDay

Administrative
Staff member
Staff
VIP
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:

Internet Name

New member
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);
 

huab

New member
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
 

Similar threads

Top