Repository navigation
Exit levels on the wrong side of the entry are kept - #434
Merged
Merged
Conversation
A strategy.exit stop / limit on the wrong side of its entry was dropped unless the exit was re-placed every bar or placed with its trade open. On TradingView such a leg is already breached when the entry fills and fills at once: an exit placed while flat for a long limit entry, its stop 64,066.01 above the 63,974.01 fill, closes the trade at that fill on the entry bar (a public strategy). The drop and the call-cadence tracking behind it are removed. Co-authored-by: Cursor <cursoragent@cursor.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: fa7b1417-f5db-4247-a212-db3cc49445c2) |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
A
strategy.exitstop / limit on the wrong side of its entry was dropped unless the exit was re-placed every bar or placed with its trade already open. The drop was a heuristic ("variables scoped in an if-block are na on TradingView"), detected through the call cadence of eachstrategy.exitcall site.On TradingView such a leg is already breached when the entry fills, and it fills at once. Example from a public strategy (BINANCE:BTCUSDT 1h): an exit placed while flat for a long limit entry, with its stop at 64,066.01 above the 63,974.01 fill, closes the trade at that fill on the entry bar.
Change
processExitOrdersis removed, along with the cadence tracking behind it:_isPersistent,_coversOpenTrade,_exit_call_history, and the exit call-site fallback counter.calc_on_order_fillsrun after a fill, exit levels snap to the tick grid relative to the fill point's price, as entries and orders already do since calc_on_order_fills: the script runs again after the bar points with fills #433.Tests
tests/namespaces/strategy/exit-wrong-side.test.ts(2 tests): a stop above a long entry and a take-profit below it both fill at the entry fill on the entry bar. Both fail ondev.Results against TradingView (compared with
dev)Note
Medium Risk
Changes core
strategy.exitevaluation and removes cadence-based heuristics, which can shift trade counts on real strategies but is covered by new regression tests.Overview
strategy.exitno longer drops stop/limit legs that sit on the “wrong” side of the entry. TradingView treats those as already breached when the entry fills and closes immediately at the fill; PineTS previously stripped them using call-site cadence heuristics (_isPersistent,_coversOpenTrade,_exit_call_history, synthetic callsite IDs).That machinery is removed from
exit.ts,types.ts, andprocessExitOrdersinutils.ts, along with strategy-state initialization for exit cadence maps.Mintick snapping for exit prices now uses
context._fillPointPricewhen the script re-runs after a fill (calc_on_order_fills), matching how entries and orders already round relative to the fill point.Tests in
exit-wrong-side.test.tscover a long with stop above entry and take-profit below entry—both should exit on the entry bar at the entry fill price.Reviewed by Cursor Bugbot for commit 793cfd1. Bugbot is set up for automated code reviews on this repo. Configure here.