TradingView backtesting guides

Position Size Calculator

Divide your risk budget by the estimated loss per unit, then round down to a tradable quantity. Include fees before comparing the result with a TradingView trade plan.

Trade assumptions

Use USD throughout. A unit is one share or an equivalent linear asset unit with a multiplier of 1. Costs per unit can include commissions and a slippage allowance for entry plus exit; do not count the same fee twice.

Estimated position

Quantity after rounding down

19 units

Risk budget
$100.00
Stop distance per unit
$5.00
Unit risk including costs
$5.10
Quantity before rounding
19.21568627
Planned loss including costs
$98.90
Unused risk budget
$1.10
Position value at entry
$2,850.00

This is a planning estimate, not an order or a guaranteed loss limit. Broker margin, available cash, minimum order value, borrow availability and contract specifications need separate checks.

Position sizing formula and units

Risk amount is account equity multiplied by the selected risk percentage. Stop distance is the absolute difference between entry and stop. For a multiplier of 1, that price distance is also the price loss per unit. Add estimated costs per unit before dividing the budget.

Risk budget = equity × risk percentage ÷ 100

Unit risk = |entry price − stop price| + round-trip costs per unit

Raw quantity = max(0, risk budget − fixed round-trip fees) ÷ unit risk

Tradable quantity = floor(raw quantity ÷ quantity increment) × quantity increment

Planned loss = tradable quantity × unit risk + fixed round-trip fees

If the rounded quantity is below the minimum order quantity, the result is zero and the assumed trade is skipped. Its planned loss and fees are zero. The calculation uses the stop as an assumed exit price; an actual fill may differ.

A stocks position size example with fees

Assume a $10,000 account, a 1% risk budget, a long entry at $150 and a stop at $145. The price loss is $5 per share. With $2 in fixed round-trip fees and $0.10 in round-trip costs per share, the calculation leaves $98 for variable risk: $98 ÷ $5.10 = 19.21568627 shares. Whole-share trading rounds this down to 19.

Hypothetical outcomes at the assumed stop price
AssumptionsSharesPlanned lossUnused budget
No costs, whole shares20$100.00$0.00
$2 fixed + $0.10 per share19$98.90$1.10
Same costs, increment of 10 shares10$53.00$47.00
Same costs, minimum of 25 shares0$0.00 (skip)$100.00

Rounding 19.21568627 up to 20 would estimate a $104 loss including costs, beyond the $100 budget. The 19-share position has a $2,850 entry value. A $100 risk budget does not mean buying only $100 of stock.

Fixed fractional position sizing

A fixed fraction keeps the chosen risk percentage constant while the dollar budget changes with account equity. At 1%, a $10,000 account allocates $100; after equity falls to $9,000, it allocates $90. Recalculate quantity using the current equity, stop and costs. The default 1% is an example, not a recommended allocation.

CME Group's position sizing explanation connects stop placement with the account amount at risk. Choosing the stop to justify a larger position reverses that process. This calculator does not decide whether a stop or risk percentage fits your strategy.

When the number needs another check

  • Equal entry and stop prices create a zero denominator. The tool shows an error instead of an unlimited position.
  • A long loss stop belongs below entry; a short loss stop belongs above it. Direction errors are rejected.
  • Negative costs, missing inputs and non-finite values do not produce an actionable quantity. Fees that consume the entire budget produce zero units.
  • Minimum quantity and quantity increment are separate broker rules. A minimum order value is another rule and is not calculated here.

The SEC's stop-order bulletin explains why a stop price is not a guaranteed execution price. A gap beyond the stop can increase the loss; a stop-limit order may not fill. Short positions also have borrowing and loss risks that this formula does not model.

For forex lot and pip conversions, use the forex lot size calculator and verify the conversion inputs. Futures and crypto derivatives need their own contract multiplier and settlement rules. This general calculator does not convert currencies or estimate liquidation.

Check the plan in TradingView, then record the outcome

Compare the calculated units with the strategy's actual order quantity. TradingView distinguishes a fixed quantity from cash or percentage-of-equity sizing. A 1% position value is different from risking 1% at a stop. Verify the exit price, symbol units, commissions and slippage settings against the official strategy documentation.

Pineify's Pine Script AI Coding Agent can help write and revise the quantity and exit logic for you to review in TradingView. In Trading Journal, record the planned risk amount, quantity and stop, then compare them with the closed trade and your review notes. These are separate steps; this calculator does not send orders or transfer its results automatically.

Frequently asked questions

Is risk per trade the same as position value?

No. A hypothetical 19-share position entered at $150 has a $2,850 position value. With a $145 stop, $0.10 of round-trip costs per share and $2 of fixed round-trip fees, the planned loss is $98.90. Position value measures exposure; planned loss estimates the loss at the assumed exit.

Can I use fractional shares or a minimum order quantity?

Yes. Set the quantity increment and minimum quantity to your broker rules. The tool rounds down to a multiple of the increment. If the result is below the minimum, it returns zero. The calculator supports increments with up to eight decimal places; it does not check broker availability or minimum order value.

Does the stop price guarantee my maximum loss?

No. A stop order can execute away from its trigger price, and a stop-limit order can remain unfilled. Gaps, slippage, changing fees and borrowing costs can make actual losses exceed the plan. The per-unit cost allowance is an estimate, not a loss guarantee.

Does this work for forex, futures or crypto derivatives?

This calculator assumes each one-dollar price move creates one dollar of profit or loss per unit, with all money inputs in USD. Forex lots, futures point values, inverse contracts and currency conversion require instrument-specific calculations. Do not enter a contract count as though it were a share count.

Educational calculations only, not investment advice. Examples are hypothetical. Source references checked October 17, 2026.

Review your strategy's position units

Bring your risk budget, stop rule and quantity increment to Pineify's AI Coding Agent. Review the generated logic and test its behavior in TradingView before using it.

Explore Pine Script AI Coding Agent