Position sizing & stops
Risk-first sizing bounded by capital, liquidity and exchange rules; ATR/structure/hybrid stops; risk-reward and trailing targets; precision-safe rounding.
Sizing answers one question: how much can this trade lose, and how many units does that allow once liquidity, capital and exchange rules are honored. The number is deterministic and conservative — when constraints conflict, the tightest one wins.
Risk-first sizing
Size is computed by the risk engine, never by the strategy or the LLM. It starts from the amount you are willing to lose, then the stop distance fixes the quantity.
One unit is assumed to lose the stop distance if the stop fills exactly. Risk amount divided by that distance gives the quantity.
- fraction of equity at risk, e.g. 0.005 = 0.5%
The real loss per unit is wider than the stop distance: adverse slippage and the exit fee are added before dividing.
stop_distance = abs(entry_price - stop_price)
slip_per_unit = entry_price * adverse_slippage_percent
exit_fee_per_unit = stop_price * exit_fee_rate
loss_per_unit = stop_distance + slip_per_unit + exit_fee_per_unit
raw_quantity = risk_amount / loss_per_unitThe final quantity is a minimum
The smallest of every binding constraint wins. A generous risk budget never overrides a thin pool or an exchange minimum.
The final quantity must respect, in code:
| Bound | Source |
|---|---|
| Capital | Available quote balance, reserve, max allocation % |
| Liquidity | Order-book depth — see Liquidity & slippage |
| Exposure | Portfolio heat, per-asset / per-strategy caps |
| Exchange | Min/max amount, min cost, step size, tick size |
Stops
A fixed-percentage stop is simple but not adaptive. ATR and structure stops adapt:
- ATR multiplier (backtested)
- average true range over n periods
Take the widest of the candidate distances so the stop is never tighter than volatility, structure or the spread allow.
A trade is rejected when the stop is unsafe:
- stop distance is zero, or the stop is at/above entry for a long;
- distance is below the minimum market movement, spread or slippage buffer;
- rounded quantity violates exchange rules or pushes risk over the limit;
- no reliable invalidation level exists.
Take-profit & trailing
- target reward-to-risk ratio
The trailing stop only ratchets up, locking in gains as the high-water mark rises.
Partial exits track remaining quantity after each fill, e.g. 25% at 1R / 2R / 3R, the rest trailed.
Exchange precision & rounding
Round down to a legal increment, then recompute the planned risk on the rounded quantity — rounding can change it.