You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Added
Margin simulation (margin_long / margin_short), modeled from
TradingView's public margin documentation (design record: dev-docs/margin-plan.md; broker doc: docs/strategy-broker.md §9):
Order gating — an exposure-increasing fill whose resulting position
would require more equity than is available at the fill price is rejected
outright (never reduced), per the v6 migration guide. Closes, exit
brackets, and the reducing leg of a netting order are never gated.
Margin calls — walking the bar's assumed intrabar path, the broker
force-closes 4× the quantity needed to cover a margin deficit (TV's rule
for "preventing constant Margin Call events"), capped at the whole
position, booked through the normal FIFO close path. Not a halt: pending
orders and exit brackets survive.
strategy.margin_liquidation_price now reports the live liquidation
level (was a hardcoded na): na while flat, when the side's margin is 0,
or for a fully-funded long.
BREAKING (behavior): margin defaults are now the Pine v6 100/100
(was: no margin model, i.e. the v5 0/0). Strategies that open positions
larger than their equity — or shorts that lose enough — now get rejected
entries and margin-call liquidations, exactly as on TradingView v6. To keep
the old unlimited-buying-power behavior, declare strategy(..., margin_long = 0, margin_short = 0) (the migration guide's
own escape hatch).