Repository navigation
fix(engine): emit TV same-bar close+reverse sequencing under frozen default sizing - #146
Merged
Merged
Conversation
…izing Generalize the TV-pinned SHORT-seed default-FIFO close collision oracle from its fixed-qty exact book to frozen PERCENT_OF_EQUITY / CASH default sizing with unequal seed/entry quantities (finding 272; derivation evidence/mc-timing-and-sequencing-derivation-20260812.json, closeReverseSeq, fitted 25/25 exact on alpha-forge-liquidity-matrix-v2). TV rule: with a SHORT seed qty S (entered on an earlier bar) and the exact same-bar book entry(Long); entry(Short); close(Long)[no-op]; close(Short)[frozen target S], all filling at the next open P, TV emits (1) the old short S exiting via order 'Long', (2) a zero-PnL dur-0 LONG round trip qty L (frozen default qty) 'Long'->'Short', (3) a second zero-PnL dur-0 LONG round trip qty min(S, L) 'Close entry(s) order Short'->'Short', and (4) an end-of-bar SHORT of exactly max(0, L - S) under the final entry's id — the real opposite entry is not queued; ordinary signal processing resumes from that position. Engine changes (all five touch points in src/engine_fills.cpp): - exact-book tagging: qty-type-aware seed gate (FIXED keeps the constant default==seed equality; PERCENT/CASH require the complete placement-frozen snapshot and matching frozen qtys on both entries); the projected final-short admission generalizes 2*seed.qty to L + min(S, L) and, for PERCENT (pct<=100), additionally mirrors the KI-54 frozen reversal re-check without its fill-time epsilon so a tagged book can never be half-declined mid-transaction. - materialization live check + fill: the close order materializes its placement-frozen target CAPPED at the live long book, min(S, L). - final-short live check: accepts lot2 == min(S, lot1) and position == lot1 + lot2. - final-short kernel: closes both LONG lots and re-opens SHORT with the residual lot1 - lot2 = max(0, L - S) at the same fill price under the final short's id/incarnation/comment; flat when L <= S. The FIXED cohort's pinned L == S collapses every relaxed gate to the old equalities and residual 0 (byte-identical; test_short_seed_close_collision unchanged). #143 dead-strategy.close, the declined-reversal close-leg suppression, gap-reject, and pyramiding paths are untouched; non-collision stale closes are still Removed. New unit coverage: tests/test_short_seed_collision_percent.cpp (percent remnant L>S with follow-up close of the remnant, percent flat L<=S, CASH remnant, gap-up KI-54 decline non-trigger control, partial-close non-trigger control). Full ctest: 125/125. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
luisleo526
added a commit
that referenced
this pull request
Aug 12, 2026
…sal fill bar's open (#147) * fix(engine): fill stale prior-bar exit brackets marketable at a reversal 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 <[email protected]> * corpus: advance to the stale-exit regenerated run Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gate
pr-gatePASS — engine corpus zero regressions, scraped entering excellent+strong >= leaving.Verdict:
/Users/haoliangwen/code/pineforge-lab/pr-gate-verdict.json🤖 Generated with Claude Code