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.
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)