TradingView event strategy research

Dividend capture strategy: test the trade and the cash ledger

A dividend capture strategy buys shares before an announced ex-dividend date and sells after entitlement has been established. The dividend alone is not the return: a price decline and execution costs can outweigh it. A useful test freezes the event information available before entry, defines an exit independently of later price recovery, and adds cash dividends exactly once to price profit or loss.

See the decision guide

Buy before the ex-date, not when the payment arrives

For an ordinary US cash dividend, Investor.gov explains that buying on or after the ex-dividend date misses that payment; buying before it establishes entitlement. The record date identifies shareholders on the company books, while the payable date is when the distribution is due. Use the announced exchange ex-date instead of deriving it from an old settlement shortcut. Special distributions and due-bill arrangements can follow different rules and are excluded from this baseline.

  • Archive the issuer announcement URL, publication timestamp and timezone, the time your system received it, ex-date, declared cash per share, currency, record date and payable date.
  • Set knownAt to the later of publication and receipt. An announcement dated before entry is insufficient if the exact information only reached the system after the decision.
  • Preserve dated amendments. Before entry, use only the version then available. After entry, record a cancellation or reduction as a separate event; do not rewrite the original decision.

A daily rule that can actually place the entry in time

This illustrative long-only rule uses standard regular-session 1D candles for one stock and one ordinary cash-dividend event. With the default bar-close strategy calculation, submit the buy at the close two trading sessions before the ex-date so it can fill at the following session open, still before the ex-date. The prior session close is too late for that same default next-open model. Trading sessions, holidays and halts must come from the exchange calendar.

  • If the ex-date is Friday, a normal five-session week gives a Wednesday close decision, Thursday open entry, Friday close exit decision and Monday open exit for N = 1. A holiday changes the actual dates.
  • This rule has no protective stop. Price exposure continues overnight and across the weekend. A halt can delay a sell beyond the intended exit; mark unresolved trades as open rather than inventing a fill.
DecisionBaseline rule
EligibilityThe archived announcement was available strictly before the decision close. Require a confirmed ordinary cash event and sufficient funds for 100 shares plus costs.
EntrySubmit one market buy at the selected decision close. Verify the actual fill occurred before the ex-session opened. No pyramiding or repeated entry.
ExitCount the ex-session as post-ex bar 1. After N completed post-ex trading bars, submit a market sell for the next available open. N = 1 is the baseline.
Price recoveryDo not wait indefinitely for price to regain the purchase price. A recovery target or protective stop is a separate variant requiring explicit rules.
Late announcementSkip when knownAt is at or after the required decision close. Do not backdate the order to make the event eligible.
Revision after entryThis baseline keeps the scheduled exit. Record any reduced or cancelled cash amount in the ledger; do not discard the resulting loss.

Pine Script: audit one pre-announced event

The script below models the price leg only. The timestamps are fictional US session examples, not a dividend announcement for the selected chart. Replace them with documented values and enable the checkbox. Keep dividend adjustment off. Match the decision input to an actual daily bar close and the ex-session input to that daily bar opening timestamp. Exact equality deliberately prevents a missing event bar from silently becoming a later event.

  • The daily position from the preceding bar must already be positive at the ex-session. A buy first filled on the ex-date fails the audit. Load the decision bar and enough later history for the exit to fill.
  • The script cannot enforce standard candles, regular sessions, dividend adjustment settings or real announcement accuracy. Confirm those settings manually. The $1 commission per order and two adverse ticks per fill are assumptions.
  • The eligible-share plot is a reconciliation aid, not money added to Strategy Tester equity. Export the completed trade and join its entry and exit prices to the cash ledger below.
  • request.dividends() supplies dividend series data. Its historical event placement does not prove that an upcoming date was known at an earlier decision. Do not shift a discovered event backward or use future-looking data to generate the buy.
Final Pine v6 source checked with the Pineify syntax checker. This validates syntax, not entitlement, fills, event authenticity or strategy performance.pine
//@version=6
strategy("Dividend capture: single-event price leg", overlay = true,
     initial_capital = 100000, pyramiding = 0,
     default_qty_type = strategy.fixed, default_qty_value = 100,
     margin_long = 100, commission_type = strategy.commission.cash_per_order,
     commission_value = 1, slippage = 2,
     calc_on_every_tick = false, calc_on_order_fills = false,
     process_orders_on_close = false)

bool verified = input.bool(false, "I verified the event and chart settings")
int knownAt = input.time(timestamp("03 Feb 2025 12:00 -0500"), "Announcement available at")
int decisionClose = input.time(timestamp("05 Feb 2025 16:00 -0500"), "Entry decision close")
int exOpen = input.time(timestamp("07 Feb 2025 09:30 -0500"), "Ex-session opening timestamp")
int holdBars = input.int(1, "Completed post-ex daily bars", minval = 1)

if not timeframe.isdaily or timeframe.multiplier != 1
    runtime.error("Use standard regular-session 1D candles, dividend adjustment off.")
if verified and (knownAt >= decisionClose or decisionClose >= exOpen)
    runtime.error("Require announcement availability before decision, before ex-session.")

bool entrySignal = verified and barstate.isconfirmed and time_close == decisionClose
if entrySignal and strategy.position_size == 0
    strategy.entry("Capture", strategy.long)

var int exBar = na
var float eligibleShares = 0.0
if verified and time == exOpen
    exBar := bar_index
    if strategy.position_size > 0 and strategy.position_size[1] > 0
        eligibleShares := strategy.position_size
    else
        runtime.error("No verified pre-ex holding. Inspect entry timing and funding.")

if verified and time > exOpen and na(exBar)
    runtime.error("Ex-session bar missing or timestamp mismatch. Audit this event.")

if barstate.isconfirmed and strategy.position_size > 0 and not na(exBar)
    if bar_index - exBar + 1 >= holdBars
        strategy.close("Capture")

plotshape(entrySignal, title = "Entry order decision", style = shape.triangleup,
     location = location.belowbar, color = color.blue, size = size.small)
plot(eligibleShares, "Shares for external cash ledger", display = display.data_window)

One dividend, two valid accounting paths

TradingView describes its dividend-adjusted chart as a total-return view. For an executable cash-ledger study, use fills without dividend adjustment and add the actual cash distribution once. A separate total-return series can serve as a benchmark, but adding another dividend to its already-adjusted return duplicates income. Never substitute adjusted historical prices for the cash amounts paid to buy and sell shares.

  • Let Q be eligible shares, Pb and Ps actual fill prices, D actual gross cash per share, C explicit commissions and other costs, and W withholding in the same currency. Net economic P&L = Q × (Ps - Pb) + Q × D - C - W.
  • If actual fills already include spread and slippage, do not subtract them again. If modeling from midprices instead, disclose and subtract those execution costs separately.
  • Split-adjusted historical prices need consistent share counts and dividend-per-share units. This single-event example excludes splits, stock distributions and currency conversion during the holding window. A multi-event study must reconcile those explicitly.
MethodDividend treatmentUse here
Price fills plus cash ledgerPrice P&L + eligible shares × actual dividend - costs - withholding.Primary trade accounting.
Dividend-adjusted total-return seriesDistribution effects are already reflected in the series methodology.Separate benchmark; do not add cash dividends again.
Adjusted-price gain plus cash dividendThe same distribution enters both components.Reject as double counting.

Worked cash ledger: a $50 dividend can accompany a loss

Assume 100 shares bought at $50.02 and sold at $49.68. These hypothetical fills already include adverse execution movement from reference prices of $50.00 and $49.70. The ordinary dividend is $0.50 per eligible share; commission is $1 each way. Assume no withholding, financing, currency conversion or other charges. This is arithmetic, not a historical trade or expected return.

  • Before payment, realized trading cash is $4,967 - $5,003 = -$36 and the dividend receivable is $50. When $50 is paid, cash becomes +$14 and the receivable becomes zero. Payment moves value between accounts; it is not a second profit.
  • If an illustrative $7.50 is withheld, net payment is $42.50 and net P&L becomes $6.50, or 0.1299% of $5,003. This amount is a sensitivity assumption, not a tax rate or tax advice.
  • With the same dividend and $2 costs, the break-even sale price is $50.02 - $0.50 + $2 / 100 = $49.54. A distribution does not prevent a sale below that price.
  • Use declared D only for a pre-trade scenario. Final P&L uses the amount actually owed and paid; keep unpaid or disputed amounts identified. Do not reinvest receivables before the cash is available.
Ledger itemCalculationAmount
Entry cash outflow100 × $50.02 + $1-$5,003
Exit cash inflow100 × $49.68 - $1+$4,967
Price P&L before commission100 × ($49.68 - $50.02)-$34
Gross dividend receivable100 × $0.50+$50
Economic P&L after commission-$34 + $50 - $2+$14
Return on initial cash outlay$14 / $5,003 × 100+0.2798%
Alternative exit at $49.38100 × ($49.38 - $50.02) + $50 - $2-$16

Test a sample without optimizing the event history

Freeze an eligible universe, ordinary-cash-event rule, entry timing and a small set of holding windows before examining returns. Preserve missing announcements, late snapshots, suspended stocks, cancelled distributions and incomplete exits in the event count. Selecting only current dividend payers or events whose prices recovered changes the sample after observing outcomes.

  • Compare N = 1, 3 and 5 only on development events, then freeze one rule for later untouched events. Report price P&L, dividend income, costs, payment delays, event count, net average trade and the worst event separately.
  • A longer holding window adds market exposure. Compare it with a stated benchmark over identical entry and exit times before attributing gains to dividend timing.
  • A single-chart strategy does not allocate capital across simultaneous events or execute an options hedge. A portfolio study needs a separate capital, settlement and multi-asset ledger.
  • Pine Script AI Coding Agent can draft the event and exit rules for review. Strategy Optimizer can compare exposed holding-window inputs after timing and costs are audited. Its price-leg ranking must be reconciled with your cash ledger before it is called a dividend-capture result.
  • Keep knownAt, ex-date and dividend facts fixed during parameter search. Never optimize a historical announcement timestamp or use one event to select a profitable holding period.
Where Pineify fits

Pine Script AI Coding Agent

Draft a Pine event strategy from explicit availability, entry and exit rules, then review its timestamps and reconcile exported trades with your dividend ledger.

Also useful: Strategy Optimizer. Compare strategy-input combinations after validating the price leg. Maintain cash dividends and payment timing in a separate reconciled ledger.

Draft dividend event rules

Frequently asked questions

Educational research, not investment or tax advice. All example prices, dates and amounts are hypothetical. No dividend-capture performance is claimed. Trading can lose money; syntax validation and backtests do not establish future returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.