Skip to content

Keep within-cap same-direction entries co-queued with a deferred close#89

Merged
luisleo526 merged 1 commit into
mainfrom
fix/close-coqueue-pyramiding-cap
Jul 10, 2026
Merged

Keep within-cap same-direction entries co-queued with a deferred close#89
luisleo526 merged 1 commit into
mainfrom
fix/close-coqueue-pyramiding-cap

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

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_placement snapshot (mirrors the fill-time gate arithmetic; refreshed on strategy.order re-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)

  • REDs proven by stash-cycle: under-cap KEEP cases fail pre-fix; probe65/bracket/over-cap/carry/opposite characterization rows pass pre- and post-fix.
  • Full ctest 88/88 (87 + new suite test_close_all_coqueued_entry).
  • Corpus gate 252/252 ok — 240 excellent / 11 strong / 1 anomaly (+1 excellent vs baseline: pyramid-cash-fractional; both cap probes exact 732=732 / 1188=1188; pyramid-deferred-flip cAbs 2→1).
  • Private validation full sweep (412): stable error inventory, 1 UP / 0 DOWN (masayanfx-scalping weak→moderate), run with the pending codegen change stashed for clean attribution.

🤖 Generated with Claude Code

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 luisleo526 merged commit 98ad849 into main Jul 10, 2026
5 checks passed
@luisleo526 luisleo526 deleted the fix/close-coqueue-pyramiding-cap branch July 10, 2026 19:14
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>
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