Close stale deferred flip entries without reopening#83
Merged
Conversation
A pending stop/limit ENTRY that reached its trigger while an OPPOSITE position it did NOT open was live performed a full reversal (close the opposite + open its own direction) whenever created_position_side != FLAT. The close-only path in apply_entry_order_fill fired only for the created_position_side == FLAT bracket (probes 80-87), so a same-id stop armed during a PRIOR position cycle — one that survives a flip to the opposite side and later triggers against that new position — reopened a fresh position at the stale stop level. TradingView instead closes the flipped position and re-arms the entry: the reduce leg fires at the touch, the open leg is superseded by the same-bar same-id re-issue and re-arms at the modified level (filling later, or never). Fix: gate close_only on `created_position_side != position_side_` — a reduce-only flip for any priced entry not placed in the cycle of the position it now reverses (covers both the flat bracket and the deferred-flip carry). The created != FLAT case routes through flip_market_position_to(close_only=true), which closes the whole opposite position and stays flat instead of opening. A genuine same-cycle reverse (created_position_side == the reversed side) still opens its new leg; deferred-flip entries that fire from FLAT are untouched. Validation: - ctest 82/82 (adds test_deferred_flip_carry_close_only, fails pre-fix). - Corpus 239 excellent / 12 strong / 1 anomaly (unchanged tally). - Deferred-flip / same-id sibling probes byte-identical. - Only 3 percent-of-equity / cash strategies change, in equity-sized qty at the ~1e-6 float level (identical entry/exit times + prices); all tiers, coverage, and gated deltas preserved. Co-Authored-By: Claude Opus 4.8 <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.
Summary
Validation