Days Till X Dividend For ThinkOrSwim

Fitzman

New member
“Dividend capture strategy” returns are the trading technique of buying a stock just before the dividend is paid, holding it just long enough to collect the dividend, then selling it. If you can sell it for as much as you paid, you have “captured” the dividend at no cost.

To be eligible to receive dividends, you have to own the stock at least one trading day before the dividend payment date.
Therefore, is it possible to create a watchlist column displaying the ex div date - either date displayed and/or the number of days until ex div date?

I know the actual dividend date is displayed as an event in the chart, and the ex div date can be selected as a visible point in the TOS app, but I cannot seem to find it as a watchlist item.

IxLIKqy.jpg


Thank you,
Fitz
 
Last edited by a moderator:
You can try this:
b3mNJmc.png


Code:
# WatchList of Label Days Till X Dividend
# If over 30 days away shows 30
# Mobius
input DaysTillXdiv = 30;

def LastDividendBar = AbsValue(GetEventOffset(Events.DIVIDEND, 0));
def NextDividend = if isNaN(LastDividendBar) then 0 else LastDividendBar;
AddLabel(NextDividend == DaysTillXdiv, "Dividend More than 30 days out", color.white);
AddLabel(NextDividend <= DaysTillXdiv-1 and NextDividend > 0, "Dividend in " + NextDividend + " days", Color.Red);
 
Last edited by a moderator:
I thought I would add an improvement here, with scripts tested in charts not a watchlist.

The script was tested with stocks scanned for:
volume > 500K
PE 4 - 20
last > 10
Dividend yield 4 - 20

Rich (BB code):
#hint: Label days since last dividend and days until next dividend, if more than look_ahead_days away state that it is more. If database has no next dividend then no label.

# Credits:
#     Mobius
#     northdecoder 4/12/24

input look_ahead_days = 30;
#hint look_ahead_days: Compare to NextDividend date, add white label for more, and red label for less than.

# # #
# look back for the last dividend
def LastDividendBar = AbsValue(GetEventOffset(Events.DIVIDEND, -1));

# if there were no dividends then set to infinite time 
def DaysSinceLastDividend = if IsNaN(LastDividendBar) then
                               Double.POSITIVE_INFINITY
                               else LastDividendBar;

AddLabel(1,
         DaysSinceLastDividend + " trading days since last dividend ",
         Color.YELLOW);

# # #
# look forward for the next dividend
def NextDividend = AbsValue(GetEventOffset(Events.DIVIDEND, 0));
AddLabel(NextDividend >= look_ahead_days,
         "dividend more than " + look_ahead_days + " days out",
         Color.WHITE);
AddLabel(NextDividend <= look_ahead_days - 1 and NextDividend > 0,
         "Dividend in " + NextDividend + " days",
         Color.RED);
 
This strategy seems conservative way to make a few bucks. I like it. The obvious thing that would **** is if the price of the stock drops after you buy in to grab the dividend. Any counter measures?
 
This strategy seems conservative way to make a few bucks. I like it. The obvious thing that would **** is if the price of the stock drops after you buy in to grab the dividend. Any counter measures?
Obviously, there is no guarantees. But to stack the deck in your favor, you would want to populate this strategy with strong high-value trending stocks.

As you are a VIP member, to find those types of stocks, you can start here:
https://usethinkscript.com/threads/trending-trade-setups.18264/

For others, review your daily and weekly charts with your favorite trend/momentum indicator:
https://usethinkscript.com/threads/a-serving-of-trend-and-momentum-indicators-for-thinkorswim.4880/
 
I thought I would add an improvement here, with scripts tested in charts not a watchlist.

The script was tested with stocks scanned for:
volume > 500K
PE 4 - 20
last > 10
Dividend yield 4 - 20

Rich (BB code):
#hint: Label days since last dividend and days until next dividend, if more than look_ahead_days away state that it is more. If database has no next dividend then no label.

# Credits:
#     Mobius
#     northdecoder 4/12/24

input look_ahead_days = 30;
#hint look_ahead_days: Compare to NextDividend date, add white label for more, and red label for less than.

# # #
# look back for the last dividend
def LastDividendBar = AbsValue(GetEventOffset(Events.DIVIDEND, -1));

# if there were no dividends then set to infinite time
def DaysSinceLastDividend = if IsNaN(LastDividendBar) then
                               Double.POSITIVE_INFINITY
                               else LastDividendBar;

AddLabel(1,
         DaysSinceLastDividend + " trading days since last dividend ",
         Color.YELLOW);

# # #
# look forward for the next dividend
def NextDividend = AbsValue(GetEventOffset(Events.DIVIDEND, 0));
AddLabel(NextDividend >= look_ahead_days,
         "dividend more than " + look_ahead_days + " days out",
         Color.WHITE);
AddLabel(NextDividend <= look_ahead_days - 1 and NextDividend > 0,
         "Dividend in " + NextDividend + " days",
         Color.RED);
Can anyone point me to a method to input this script? Is it a custom study on a scan?
 
You can try this:
b3mNJmc.png


Code:
# WatchList of Label Days Till X Dividend
# If over 30 days away shows 30
# Mobius
input DaysTillXdiv = 30;

def LastDividendBar = AbsValue(GetEventOffset(Events.DIVIDEND, 0));
def NextDividend = if isNaN(LastDividendBar) then 0 else LastDividendBar;
AddLabel(NextDividend == DaysTillXdiv, "Dividend More than 30 days out", color.white);
AddLabel(NextDividend <= DaysTillXdiv-1 and NextDividend > 0, "Dividend in " + NextDividend + " days", Color.Red);
Cheers Ben !!
 

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
345 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