fix(engine): make dead strategy.close semantically inert - #143
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the deferred-flip carry behavior so that adding an unreachable strategy.close in Pine source cannot change runtime backtest fills. It removes the runtime dependency on the compile-time script_has_strategy_close_ AST bit, keeps that bit only for generated-code compatibility, and adds regression/characterization coverage plus runtime documentation updates.
Changes:
- Remove
script_has_strategy_close_from the deferred-flip predicate inBacktestEngine::enter_market_from_flat. - Reframe
script_has_strategy_close_as a legacy, semantically inert compatibility member in engine headers and runtime docs. - Update/add tests to prove unreachable
strategy.closeis inert and adjust characterization expectations where carry behavior is now pinned correctly.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/engine_orders.cpp |
Drops the compile-time flag from the deferred-flip carry condition so behavior depends only on order-captured runtime state. |
include/pineforge/engine.hpp |
Documents script_has_strategy_close_ as legacy compatibility only (no runtime semantic effect). |
tests/test_strategy_pyramiding.cpp |
Removes direct flag forcing and adds a metamorphic regression test for issue #141. |
tests/test_same_id_stop_replace.cpp |
Updates commentary to reflect the new deferred-flip predicate (no compile-time gate). |
tests/test_close_all_coqueued_entry.cpp |
Updates characterization to match generated-script behavior and pins expected carry outcome. |
docs/cheatsheet-runtime-and-execution.md |
Updates runtime cheat sheet to reflect that the flag no longer gates deferred-flip behavior and that brackets can arm carry behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+218
to
+221
| Bar bars[4] = { | ||
| {100, 101, 99, 100, 1000, 60'000}, | ||
| {100, 101, 99, 100, 1000, 120'000}, // L fills; arm S + XL | ||
| {100, 101, 94, 95, 1000, 180'000}, // XL closes L; S untouched |
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
script_has_strategy_close_AST bitstrategy.closecannot change bracket-exit fillsFixes #141.
Root cause
Codegen set
script_has_strategy_close_from textual AST presence, without reachability analysis. The runtime used that global bit to gate placement-time reversal carry, so adding an unreachablestrategy.closechanged later priced-entry quantities even though the executed broker commands were identical. Astrategy.exitbracket can close the carry source on its own, so the runtime decision must use the order's captured state rather than unrelated source text.Validation
countAbsDeltaregressions, 0 Excellent-to-below-Strong regressions, 0 unresolved failures