Open the app
Quantitative core

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.

position_sizing_v1
Risk amount & raw 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%
position_sizing_v1
Slippage- and fee-adjusted size

The real loss per unit is wider than the stop distance: adverse slippage and the exit fee are added before dividing.

python
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_unit

The final quantity is a minimum

position_sizing_v1
Bounded by every limit at once

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:

BoundSource
CapitalAvailable quote balance, reserve, max allocation %
LiquidityOrder-book depth — see Liquidity & slippage
ExposurePortfolio heat, per-asset / per-strategy caps
ExchangeMin/max amount, min cost, step size, tick size

Stops

A fixed-percentage stop is simple but not adaptive. ATR and structure stops adapt:

atr_stop_v1
ATR stop
ATR multiplier (backtested)
average true range over n periods
hybrid_stop_v1
Hybrid stop distance

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_v1
Risk-reward target
target reward-to-risk ratio
trailing_v1
ATR trailing stop (long)

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

position_sizing_v1
Round down to the step size, then re-validate risk

Round down to a legal increment, then recompute the planned risk on the rounded quantity — rounding can change it.

Re-validate after rounding
The order is rejected if rounding produces a cost below the minimum, a zero quantity, a planned risk above the configured limit, a quantity above the available balance, or an invalid price increment. must still clear the limit.
Prefer no trade over an unquantifiable one
If no reliable stop exists, or the post-rounding risk cannot be proven under the limit, the engine declines. A position that cannot be sized safely is not taken.