Fixed contract quantities expose a strategy to different cash losses when its protective stop distance changes. A fixed cash risk budget provides a reproducible sizing rule for instruments with a known point value. It is a sizing model, not a guarantee of maximum loss.

Worked futures example

Assume a point value of 50 dollars, a 0.25 tick and a 200 dollar risk budget. A two-point stop equals eight ticks and 100 dollars per contract, allowing two contracts. A four-point stop equals sixteen ticks and 200 dollars per contract, allowing one. A five-point stop exceeds the budget for even one contract, so the strategy skips entry.

Sizing Pine Script Strategy Entries with a Fixed Cash Risk Budget
A $200 budget permits two contracts at a two-point stop or one at a four-point stop.

Pine Script implementation

Round the requested stop distance upward to whole ticks before calculating risk. Multiply the resulting distance by syminfo.pointvalue and round the quantity down to whole contracts. The example assumes the symbol's profit currency and risk budget currency match, and a whole-contract instrument with valid positive point value. The moving average crossover is merely an illustrative entry trigger.

//@version=6
strategy("Cash risk sizing example", overlay=true, pyramiding=0)
riskCash = input.float(200, "Risk budget", minval=1)
stopPoints = input.float(2, "Stop distance", minval=0.01)
ticks = math.max(1, math.ceil(stopPoints / syminfo.mintick))
distance = ticks * syminfo.mintick
riskPerContract = distance * syminfo.pointvalue
qty = math.floor(riskCash / riskPerContract)
signal = ta.crossover(close, ta.sma(close, 20))
if signal and strategy.position_size == 0 and qty >= 1
    strategy.entry("L", strategy.long, qty=qty)
    strategy.exit("LX", "L", loss=ticks)

The loss parameter of strategy.exit specifies ticks relative to the entry price. The exit is linked to entry L. With default strategy behavior, market entries are generally modeled at the next available tick, normally the next bar open in historical testing. TradingView's broker emulator is not a live execution venue. Margin, quantity increments, currency conversion and broker constraints need separate validation.

Testing the budget

Check distances of two, four and five points and non-tick-aligned inputs such as 2.01, which rounds to 2.25 for a 0.25 tick. At 50 dollars per point the resulting risk per contract is 112.50, so quantity is one. Compare modeled stop losses with realized losses after fees and slippage. Include gap-through-stop cases and use Bar Magnifier where appropriate. A stop may fill worse than its trigger; commissions and currency movements can exceed the nominal budget. This educational example is not a complete trading system.

Official reference: platform documentation.

This example has not been compiled or backtested here. Trading involves risk of loss.

To adapt this strategy idea, contact us about Custom TradingView strategy Development Services.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.