Skip to content

Exit levels on the wrong side of the entry are kept - #434

Merged
alexgrover merged 1 commit into
devfrom
fix/exit-wrong-side-levels
Oct 14, 2026
Merged

alexgrover merged 1 commit into
devfrom
fix/exit-wrong-side-levels

Conversation

@alexgrover

@alexgrover alexgrover commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

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 already open. The drop was a heuristic ("variables scoped in an if-block are na on TradingView"), detected through the call cadence of each strategy.exit call 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

  • The wrong-side drop in processExitOrders is removed, along with the cadence tracking behind it: _isPersistent, _coversOpenTrade, _exit_call_history, and the exit call-site fallback counter.
  • In a calc_on_order_fills run 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 on dev.

Results against TradingView (compared with dev)

  • Public strategies:
    • ema200-regime-bos-choch: first divergence trade 1 → 11;
    • harmonic-pulse-xabcd: trade 2 → 9, and its trade count now matches TradingView's (48);
    • bull-wolf and hvn-fade: same first divergence, trade counts change by one (hvn-fade now matches TradingView's 23).
  • Controlled cases and premium backtesters: no change.
  • Unit suite: all committed tests pass. Oracle suite: 0 regressions.

Note

Medium Risk
Changes core strategy.exit evaluation and removes cadence-based heuristics, which can shift trade counts on real strategies but is covered by new regression tests.

Overview
strategy.exit no 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, and processExitOrders in utils.ts, along with strategy-state initialization for exit cadence maps.

Mintick snapping for exit prices now uses context._fillPointPrice when 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.ts cover 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.

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>
@cursor

cursor Bot commented Oct 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@alexgrover
alexgrover merged commit ae5a747 into dev Oct 14, 2026
2 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant