fix(fills): normalize qty_percent when freezing a deferred layered exit qty#77
Merged
Merged
Conversation
…it qty reconcile_deferred_layered_exits froze each leg's qty to its reserved slice but left the 100% sibling's qty_percent at 100. On a later re-arm of the partial sibling, the compute_exit_reserved_qty guard read that stale 100 as a still-pending FULL exit, dropped the re-issued partial, and the 100% leg re-expanded to flatten the whole position at its stop — over-closing a layered TP1(50%)+TP2(100%) bracket that was armed while flat (the deferred path; live-armed groups normalize at arm time). Set qty_percent consistent with the qty reconcile already froze (mirrors the live-armed normalization in compute_exit_reserved_qty). The change is gated by reconcile's leg_count>=2 + has_partial condition, so live-armed layered exits and non-layered brackets are untouched. Gate (R7, fresh context): cmake pineforge clean; ctest 79/79; run_corpus 239 exc/12 strong/1 anomaly fail=0 (byte-identical corpus); data sweep 0 up/0 down across 8 qty_percent sentinels + 2 3commas DCA/grid, run_err=0. Co-Authored-By: Claude Opus 4.8 (1M context) <[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.
Summary
A layered
strategy.exitgroup (a partialqty_percentleg + a 100% sibling) armed while the position is FLAT goes through the deferred-reconcile pathreconcile_deferred_layered_exits(src/engine_fills.cpp:922-939). That path froze each leg'so.qtyto its reserved slice but left the 100% sibling'so.qty_percentat 100.On a later per-bar re-arm of the partial sibling, the
compute_exit_reserved_qtyguard (src/engine_strategy_commands.cpp:1023-1033) read that staleqty_percent=100as a still-pending full exit, dropped the re-issued partial, and the 100% leg re-expanded to flatten the whole position at its stop — over-closing aTP1(50%) + TP2(100%)bracket (100% single close instead of two 50% legs).Fix
Set
o.qty_percentconsistent with theo.qtyreconcile already froze (one line, mirrors the live-armed normalization atengine_strategy_commands.cpp:1020):Gated by reconcile's existing
leg_count >= 2 && has_partialcondition. Live-armed layered exits (armed insideif position_size > 0) never enter reconcile — they normalize at arm time — so they are untouched, as are non-layered brackets.Gate (fresh-context R7)
cmake --build build --target pineforgecleanctest: 79/79 passingrun_corpus.sh: 239 excellent / 12 strong / 1 anomaly,fail=0— corpus artifacts byte-identical (the deferred-layered path has no corpus coverage; goldenbracket-partial-exit-qty-percent-01is live-armed)qty_percentsentinels + 2 3commas DCA/grid: 0 up / 0 down,run_err=0The originating strategy is coverage-capped by an unrelated HTF-warmup ceiling, so this is a correctness/fidelity fix rather than a scoreboard move; ~15 data/ layered-exit strategies exercise the construct.
🤖 Generated with Claude Code