Risk management bounds how much a single trade can lose and locks in gains. Every serious strategy should set at least a stop loss.
Capital preservation is the whole game. A strategy with an excellent win rate and no stop can still be ruined by one outlier move — and a backtest run without a stop reports a drawdown you would never actually have survived.
Stop loss#
Caps the loss on a position.
| Type | Behaviour | Key parameter |
|---|---|---|
StopLossSimple | A fixed percentage from the entry price | stoploss_pct (default -5%) |
StopLossTrailing | Follows price in your favour by a fixed distance, locking in profit as the trade moves your way | trailing_pct (default 0.5%) |
StopLossAtr | Distance scales with recent volatility (Average True Range), so the stop is wider in choppy markets and tighter in calm ones | atr_multiplier (default 2.0) |
Trailing stops suit trend strategies, where you want to stay in a move that keeps going. Fixed stops suit mean-reversion, where you have a specific level that invalidates the idea.
The difference is easiest to see on a trade that runs up and then pulls back.
The ATR stop is a fixed stop whose distance is set by recent volatility rather than a flat percentage: wider when the market is choppy, tighter when it is calm, so a normal wiggle doesn't stop you out but a real break does.
Take profit#
Closes a position once it reaches a target gain.
| Type | Behaviour | Key parameter |
|---|---|---|
TakeProfitSpread | Multiple exit levels — splits the position across targets rather than closing all at once | order_spread, an array of profit_target percentages |
A spread take-profit scales out: instead of closing the whole position at one target, it closes a slice at each of several targets, banking profit along the way while leaving a runner in for a bigger move.
A worked configuration pairing a trailing stop with a two-step target:
Stop Loss: StopLossTrailing, trailing_pct: 2%
Take Profit: TakeProfitSpread
- Level 1: +5% profit → close 50%
- Level 2: +10% profit → close the remaining 50%Position sizing and leverage#
- Leverage multiplies exposure — and risk. It defaults to
1. Only raise it once you understand the liquidation math for the market you are trading. - Size positions so that hitting your stop loss costs a small, survivable fraction of the account, not a make-or-break amount.
Set the stop loss first, then size the position from it — not the other way around. "How much do I want to buy?" is the wrong first question; "how much am I willing to lose if I'm wrong?" is the right one, and it determines the answer to the first.
Reading risk in a backtest#
Backtest with the stop in place from the start, so the reported max drawdown reflects the strategy you would actually run. Adding a stop afterwards changes which trades exist, not just their outcomes — it is a different strategy, and its old results no longer describe it.