Position Sizing
The Position Sizing node answers the question "how many units should I buy?" by dividing the dollar amount you are willing to risk by the price distance between your entry and stop-loss. It enforces the fixed-fractional position sizing model: risk exactly N% of your account on every trade, regardless of volatility.
Formula
Position size is floored to a whole number of units. Bars where priceRisk ≤ 0 or the close is null produce null.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| accountEquity | number | 10 000 | Total account value in quote currency. |
| riskPercent | number | 1.0 | Percentage of account equity to risk per trade (e.g. 1 = 1%). |
| stopLossPercent | number | 2.0 | Stop distance expressed as % below entry. Used to compute priceRisk. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Input | ||
| input | (number | null)[] | Close price series (entry price at each bar). |
| Outputs | ||
| positionSize | number | null | Integer unit count to purchase at the most recent bar. |
| riskAmount | number | null | Dollar amount risked (accountEquity × riskPercent / 100). |
| entryPrice | number | null | Last valid close price used as entry. |
| stopLossPrice | number | null | Stop price: entry × (1 − stopLossPercent / 100). |
| priceRisk | number | null | Price distance between entry and stop (entry − stopLossPrice). |
| values | (number | null)[] | Per-bar position size array (floor of riskAmount/priceRisk, null if invalid). |
| timestamps | number[] | UNIX ms timestamps aligned 1-to-1 with values. |
Use Cases
Fixed-fractional sizing with Stop Loss node
Connect the close price output to Position Sizing and use the same stopLossPercent as your Stop Loss node. The positionSize output then tells the execution layer exactly how many units to place while ensuring the trade cannot lose more than riskPercent of equity.
Dynamic sizing on volatile assets
On high-volatility assets, a fixed unit count is dangerous. Position Sizing automatically reduces the unit count when the asset is expensive or volatile (large stop distance), and increases it when conditions are calm — keeping dollar risk constant across all entries.