Repository navigation
Pine v5 default margin 0; percent_of_equity capped at 100% without margin - #435
Merged
Merged
Conversation
…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>
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: e6d971e6-d4d6-4048-9bcd-883a0dbd8dde) |
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.
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_shorthas 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_marginflag is removed (the getters already treat margin 0 the same way).Without a margin model,
percent_of_equityis 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: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 ondev; the others guard existing behavior.Results against TradingView (compared with
dev)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_shortto 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_marginflag is removed;margin === 0is now the single signal everywhere (liquidation price,capital_held, margin checks).percent_of_equitysizing now caps at 100% of equity when there is no margin model (margin0), 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.tsfor 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.