Skip to content

Pine v5 default margin 0; percent_of_equity capped at 100% without margin - #435

Merged
alexgrover merged 1 commit into
devfrom
fix/v5-margin-and-equity-cap
Oct 15, 2026
Merged

alexgrover merged 1 commit into
devfrom
fix/v5-margin-and-equity-cap

Conversation

@alexgrover

@alexgrover alexgrover commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Two sizing / margin rules, found by logging strategy.default_entry_qty, equity and the position on TradingView and in PineTS (BINANCE:BTCUSDT 1h, Pine v5 and v6), and confirmed with 14 sizing probes.

Changes

Pine v5's default margin is 0. A v5 strategy without margin_long / margin_short has no margin model on TradingView. PineTS only flagged it for the reporting getters and kept margin 100% in the broker. A v5 strategy sized at 150% of equity therefore had every order rejected: controlled case 15 made 0 trades, against 109 on TradingView. The v5 defaults are now 0 in the strategy config, and the _v5_no_margin flag is removed (the getters already treat margin 0 the same way).

Without a margin model, percent_of_equity is capped at 100% of equity. With margin 0, TradingView sizes 120%, 150% and 300% of equity identically, as 10,000 / 63,465.51 = 0.158. Other settings behave differently:

  • cash sizing is not capped (15,000 of cash buys 0.236);
  • at margin 50%, 150% is used;
  • at margin 100% (the v6 default), the 150% order is rejected, as before.

Tests

tests/namespaces/strategy/margin-defaults-and-sizing.test.ts (5 tests): v5 at 150%; v6 margin 0 at 300%; v6 margin 50 at 150%; v6 default margin rejecting 150%; cash above equity at margin 0. The first two fail on dev; the others guard existing behavior.

Results against TradingView (compared with dev)

  • Controlled case 15 (1h and 1D): 0 trades → identical.
  • Sizing probes: v5 at 150%, and v6 at margin 0 with 120% / 150% / 300%, become identical. The other probes were already identical.
  • Public strategies, premium backtesters and the other controlled cases: no change.
  • Unit suite: all committed tests pass. Oracle suite: 0 regressions.

Note

Medium Risk
Changes default margin and order sizing for Pine v5 strategies and percent-of-equity logic, which can alter which entries fill versus TradingView parity fixes.

Overview
Aligns Pine v5 with TradingView by defaulting margin_long / margin_short to 0 when those are not set on a v5 script, instead of keeping 100% margin in the broker while only flagging “no margin” for reporting. The internal _v5_no_margin flag is removed; margin === 0 is now the single signal everywhere (liquidation price, capital_held, margin checks).

percent_of_equity sizing now caps at 100% of equity when there is no margin model (margin 0), so 120%/150%/300% all size like 100%; cash sizing is unchanged. v6 at 100% margin still rejects oversize orders as before.

Adds margin-defaults-and-sizing.test.ts for v5/v6 margin defaults, the cap, and cash vs percent behavior.

Reviewed by Cursor Bugbot for commit 6af287a. Bugbot is set up for automated code reviews on this repo. Configure here.

…rgin

A v5 strategy without margin_long / margin_short has no margin model on
TradingView (margin 0), but PineTS only flagged it for the reporting
getters and kept margin 100% in the broker, so a v5 strategy sized at
150% of equity had every order rejected (controlled case 15: 0 trades,
109 on TradingView). The v5 default margins are now 0.

Without a margin model, TradingView caps percent_of_equity sizing at
100% of equity: 120%, 150% and 300% at margin 0 all size 10,000 /
63,465.51 = 0.158. Cash sizing is not capped; at margin 50%, 150% is
used; at margin 100% the 150% order is rejected.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Oct 15, 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: e6d971e6-d4d6-4048-9bcd-883a0dbd8dde)

@alexgrover
alexgrover merged commit fb7fe52 into dev Oct 15, 2026
2 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 15, 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