fix(orders): defer process_orders_on_close market entry off the entry bar#51
Merged
Conversation
… bar Under process_orders_on_close, strategy.entry market orders were filled immediately at the bar close (to keep strategy.position_avg_price correct for a following strategy.exit). But that made a same-bar bias-exit fire on the entry bar, producing zero-duration trades TradingView never emits: TV processes the market entry on close, then evaluates exits on the NEXT bar. Remove the immediate same-bar execute_market_entry for plain market entries under POOC; the order goes through the normal queue and the exit is evaluated the following bar, matching TV's calc-then-fill ordering. Priced (limit/stop) entries are unaffected. officialjackofalltrades-quant-synthesis: 23 zero-duration trades -> 0; strict entry|exit match 65.0%->72.8%, price-exact 96.9%->100%. Corpus held 251 excellent / 1 anomaly; ctest 76/76 incl. test_pooc_exit_not_triggered_on_entry_bar (reverting the fix makes it fail). No new C-ABI export. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Problem
Under
process_orders_on_close,strategy.entrymarket orders were filled immediately at the bar close (to keepstrategy.position_avg_pricecorrect for a followingstrategy.exit). That made a same-bar bias-exit fire on the entry bar, producing zero-duration trades TradingView never emits: TV processes the market entry on close, then evaluates exits on the next bar (calc-then-fill).Fix
Remove the immediate same-bar
execute_market_entryfor plain market entries under POOC; the order goes through the normal queue and the exit is evaluated the following bar, matching TV's ordering. Priced (limit/stop) entries are unaffected (the existing POOC corpus probes use limit entries → unchanged).Validation
test_pooc_exit_not_triggered_on_entry_bar(reverting the fix → test fails)check_c_abi_runtime.pyRebased on #50; re-validated the combined tree (legalrice trail_price + this POOC fix): corpus 251/1, both strategies hold.
🤖 Generated with Claude Code