fix(orders): arm strategy.exit trailing stop via trail_price (absolute activation)#50
Merged
Merged
Conversation
…e activation) The engine armed a strategy.exit trailing stop ONLY when trail_points (an entry-relative tick offset) was set. A trail specified via trail_price (an absolute activation price level) — the other form Pine's strategy.exit accepts — was silently dropped: PendingOrder never carried trail_price, and every trail predicate (compute_exit_trail_state, sort/classify/evaluate paths) keyed has_trail solely on trail_points. So `strategy.exit(trail_price=close, trail_offset=...)` produced no trailing exit at all. Add a default-NaN trail_price to PendingOrder, persist it in strategy_exit, and arm the trail on (trail_points OR trail_price) everywhere. compute_exit_trail_state sets the activation level from trail_price as an absolute level (no entry-relative tick rounding); trail_points keeps precedence when both are set. legalrice2697-nse-elite (trail_price-only trailing exits): 50.0%->99.7% match vs TradingView (359/360, price-exact 100%). Corpus held 251 excellent / 1 anomaly; ctest 76/76 incl. extended test_resolve_exit_trail_fills (trail_price long+short cases; reverting the arming makes 4 CHECKs 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
The engine armed a
strategy.exittrailing stop only whentrail_points(an entry-relative tick offset) was set. A trail specified viatrail_price(an absolute activation price level) — the other form Pine'sstrategy.exitaccepts — was silently dropped:PendingOrdernever carriedtrail_price, and every trail predicate (compute_exit_trail_state, the sort/classify/evaluate fill paths) keyedhas_trailsolely ontrail_points. Sostrategy.exit(trail_price=close, trail_offset=...)produced no trailing exit at all.Fix
trail_pricetoPendingOrder(default-initialized so direct constructions that never assign it can't read an indeterminate value through the trail predicates).trail_priceinstrategy_exit; initialize it to NaN in the other order constructors.(trail_points || trail_price)acrosscompute_exit_trail_state,sort_exit_siblings_by_path_fill,sort_orders_by_fill_phase,classify_order_eligibility,evaluate_fill_price, and the no-trail path metric.compute_exit_trail_statesets the activation level fromtrail_priceas an absolute level (no entry-relative tick rounding);trail_pointskeeps precedence when both are set.No new C-ABI export (
trail_pricealready flows intostrategy_exitfrom codegen; it was simply ignored).Validation
test_resolve_exit_trail_fills(trail_price long+short; reverting the arming → 4 CHECK failures)check_c_abi_runtime.py🤖 Generated with Claude Code