Keep within-cap same-direction entries co-queued with a deferred close#89
Merged
Conversation
After a deferred full-close exit filled and flattened, the engine wiped every pending same-direction MARKET/ENTRY order. TradingView keeps the ones placed on the close's own call bar when they were within the pyramiding cap at placement: TV enforces pyramiding at order PLACEMENT, the engine at fill, and the post-close wipe was the only bridge between those semantics. PendingOrder now snapshots over_pyramiding_cap_at_placement (mirroring the fill-time gate's arithmetic, refreshed on strategy.order re-placement), and both deferred wipe sites remove a same-direction entry iff it is a prior-bar carry OR was over the cap at placement. Prior-bar carries, the immediate/process_orders_on_close cancel path, the resting-limit carve-out, the fill-time pyramiding gate, and opposite-direction (close-vs-reversal precedence) behavior are unchanged; the Remove predicate only narrows, so removals are a strict subset of the previous behavior. Evidence: pyramid-deferred-flip probe — TV fills both the session close_all exit and the co-queued under-cap entries (9 exemplars, all open-count below cap 4); same-id add at pyramiding=1 co-queued with close (probe 65) stays dropped in 366/366 TV cycles; bracket probe's over-cap re-armed stop stays dropped with no close call involved, pinning the discriminator as the pyramiding cap, not close type or id. Corpus: 240 excellent / 11 strong / 1 anomaly (+1 excellent: pyramid-cash-fractional recovers its wrongly-dropped under-cap co-queue; both cap probes stay exact; pyramid-deferred-flip improves). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
luisleo526
added a commit
that referenced
this pull request
Jul 10, 2026
…ntract plan Corrections and additions from a seven-perspective audit (TradingView docs, PineTS/PyneCore at pinned revisions, FIX/Nautilus/LEAN comparison, two codebase verifications at 98ad849, red-team, practitioner evidence; serious findings adversarially re-verified): - fix the stored-artifact claim (a whole-session 2025-05-01 run existed) and the dead PyneCore live-mode citation; re-base the audit on 98ad849 (#89) - add wait-for-entry exit deferral, slippage, trailing immediate-activation, calc_on_every_history_tick, and command-revision states incl. REJECTED_AT_PLACEMENT to the contract - record the exit REMARKS fill-first rule as working-order bookkeeping (proven by the pinned three-way bracket export); name the two deliberate TV divergences (fixed-grid quiet bars, OCA one-winner pending P8) - add the section 7 TradingView probe plan (P1-P9) and completion-gate item - pin bar_magnifier gating and digest scoping, gap-policy enumeration, quiet-bar equity marking, canonical event ordering, hash serialization, clock-event validation, silent-drop diagnostics, position_episode_id, OCA membership observability, fill-cardinality wording, restart caveat, baseline re-basing escape hatch with pinned engine/corpus/scorer hashes, and section D data/resource prerequisites Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
After a deferred full-close exit filled and flattened, the engine wiped every pending same-direction MARKET/ENTRY order. TV keeps those placed on the close's own call bar when they were within the pyramiding cap at placement — TV enforces pyramiding at order placement, the engine at fill, and the post-close wipe was the only bridge between the two semantics.
Fix:
PendingOrder.over_pyramiding_cap_at_placementsnapshot (mirrors the fill-time gate arithmetic; refreshed onstrategy.orderre-placement) consumed at both deferred wipe sites: remove iff prior-bar carry OR over-cap-at-placement. The Remove predicate only narrows → removals are a strict subset of previous behavior. Untouched: fill-time pyramiding gate, immediate/POOC cancel path, resting-limit carve-out, opposite-direction close-vs-reversal behavior.A broader candidate (call-bar exemption alone) was rejected by the corpus gate — it doubled
order-same-id-entry-close-same-bar-01(TV drops an at-cap same-id add 366/366) and regressed the bracket cap probe (over-cap re-armed stop with no close call), pinning the discriminator as the pyramiding cap, not close type or order id.Gates (author + independent fresh-context R7, both green)
test_close_all_coqueued_entry).🤖 Generated with Claude Code