Skip to content

fix(engine): fill stale prior-bar exit brackets marketable at a reversal fill bar's open - #147

Merged
luisleo526 merged 2 commits into
mainfrom
ship/stale-exit
Aug 12, 2026
Merged

fix(engine): fill stale prior-bar exit brackets marketable at a reversal fill bar's open#147
luisleo526 merged 2 commits into
mainfrom
ship/stale-exit

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Gate

pr-gate PASS — engine corpus zero regressions, scraped entering excellent+strong >= leaving.

Verdict: /Users/haoliangwen/code/pineforge-lab/pr-gate-verdict.json

🤖 Generated with Claude Code

luisleo526 and others added 2 commits August 12, 2026 22:22
…sal fill bar's open

When a reversal MARKET entry fills, TradingView still honors the STANDING
strategy.exit order whose levels were computed on the PRIOR bar from the
OLD (reversed-away) position's avg_price: if a leg is marketable at the
fill bar's open, TV fills it AT THE OPEN — a duration-0 PnL-0 trade for
the new position — and the re-priced bracket issued at that bar's close
governs afterwards.

The engine already implemented this for the gapped STOP leg via the
prearmed_market_parent_stop_gaps_at_open oracle (clean-room probe
order-market-reversal-resting-bracket-gap-01). This extends the same
provenance-gated oracle to the marketable LIMIT leg and renames it
prearmed_market_parent_bracket_gaps_at_open. A limit-leg scratch books at
the open on the unslipped limit-or-better path; the stop leg keeps its
established slipped booking. Dual-marketable brackets remain excluded
(no tape exemplar), as do POOC, COOF, magnifier, partial/sibling groups,
priced parents, and multi-child groups.

Pinned by Lab finding 278 seed (b) on
rhyme17-trendline-and-horizontal-breakout: six tape events
(2025-04-07 / 04-27 / 07-23 / 10-21 / 12-08 / 2026-01-09, UTC) where the
engine held through the fill bar and re-priced from the new avg, injecting
~+664 USD of phantom PnL versus TV's six zero trades. With the fix all six
events book TV's exact duration-0 PnL-0 trades at the bar open and the
post-event re-entry chains re-align with the TV tape
(|pnl diff| p90 16.18 -> 6.62, max 357.63 -> 85.62 on the full-year tape).

Scope: exit ORDER lifecycle only. The reverted same-bar position_size
visibility class (ycelestine ledger) is untouched — scripts observe the
same mid-bar position state as before — as are the #146 same-tick
close+reverse sequencing kernel and ordinary non-reversal exit re-issues
(position_open_bar_ / fresh-lot provenance gates).

Tests: extends test_prearmed_market_parent_gap_exit with limit-leg cells
(flat + reversal, equality-at-open, post-open controls, dual-marketable
hold, ongoing-position re-issue control, partial-qty control).
ctest 125/125 green; full corpus sweep green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@luisleo526
luisleo526 merged commit 2b1de03 into main Aug 12, 2026
7 checks passed
@luisleo526
luisleo526 deleted the ship/stale-exit branch August 12, 2026 15:13
luisleo526 added a commit that referenced this pull request Aug 12, 2026
…lined reversals + 1x-long entry-fill margin chronology (#150)

* factorial: extrema-positional-stoch-zerorange [engine]

* fix(engine): exit-bracket lifecycle across declined in-position reversals

A declined in-position opposite MARKET reversal (the KI-54/KI-72 fill
re-check declines — the tradeless reversal) cancels the live position's
standing PRICED strategy.exit brackets on TradingView. The engine kept
the original bracket live and stop-filled early, forking position state
for days on every tradeless opposite signal.

- KILL: the decline marks the position's standing priced brackets
  dormant — never the "__close__" close/close_all family, never stale
  exits bound to a not-yet-filled entry id (the #147 stale-exit family).
- DORMANT: a dormant bracket stays in the book but never matches a fill
  (classify_order_eligibility Skip in the ordinary kernel; an apply-time
  mirror in the KI-60 COOF kernel, whose candidate set is pre-classified
  before any candidate is applied, so a mid-segment kill is invisible to
  classify there).
- REVIVE-A: a fresh same-(id,from_entry) strategy.exit re-issue replaces
  the dormant bracket wholesale and arms the new call's prices (the
  ordinary replacement path — no new code).
- REVIVE-B: a margin-call partial re-registers the surviving position's
  dormant brackets at their last-armed prices.
- MC-CASCADE: when the margin-call event price already makes a revived
  full-percent default stop marketable, the entire remainder closes at
  that event price through the bracket's id on the slice bar.

Derivation: 162/162 alive-at-breach episodes, 118/118 TV stop-skips,
19/19 revive-B exact-stop fills, 18/18 cascade fills at the event
extreme; tape validation collapses the count mismatch to 0 with the
whole suite green and the corpus byte-identical.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(engine): 1x-long opening-affordability check runs at the entry fill, before same-bar intrabar exits

TradingView evaluates the margin_long=100 opening-affordability check AT
THE ENTRY FILL, chronologically before the same bar's intrabar exits.
The #149 chronology hook (margin_call_slice_before_priced_exit)
deliberately excluded 1x longs — compute_liquidation_price() is na there
— so a same-bar priced exit filled the FULL position first and the
end-of-bar one-shot opening event found the position already reduced or
gone: the "Margin call" trim row (ordinary floor-before-4x restore,
including the sub-lot one-contract fallback, filled at the RAW matched
entry base — a pnl-0 row) was lost, and the equity fork cascaded through
every later default-sized fill.

The hook now routes the 1x-long class to an opening-slice helper that
books the trim with process_margin_call's opening-affordability LONG
branch arithmetic verbatim, then lets the triggering exit close the
reduced remainder. The one-shot event is consumed only when a slice is
actually booked. Unchanged byte-for-byte: bars where no same-bar priced
exit fills (end-of-bar placement), POOC close fills, the scoped SHORT
opening event (end-of-bar plus adverse-retry), the leveraged
adverse-extreme chronology class, and every no-deficit evaluation.

The deficit class: a lot-floored percent=100 reversal admitted on an
uptick inside its floor remainder overshoots post-close equity by
tick*(qty+closed) - remainder (sub-lot -> one-contract fallback); a
commissioned explicit open reaches the same discontinuity through its
entry fee. Tape validation collapses the count mismatch (the pure
cascade family) to 0 with the whole suite green and the corpus
byte-identical.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: PineForge Factorial <factorial@pineforge.invalid>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant