Stops the strategy when its equity falls a set amount below its highest value.
strategy.risk.max_drawdown(value, type) sets a limit on how far equity can fall from its running peak. Once the fall reaches the limit, the emulator cancels every pending order, closes every open position and refuses new orders for the rest of the run.
Pass strategy.percent_of_equity as type for a percentage of the peak, or strategy.cash for an amount in the account currency. Unlike the intraday rules, a drawdown stop does not reset the next day.
Syntax
strategy.risk.max_drawdown(value: simple int/float, type: simple string, alert_message: simple string (optional)) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| value | simple int/ | required | The largest drawdown allowed, in the unit chosen by type. Must be positive. |
| type | simple string | required | How value is read: strategy.percent_of_equity for a percentage of equity, or strategy.cash for an amount in the account currency. |
| alert_message | simple string | na | Text sent with the alert when the rule stops the strategy. With na, the alert carries the default message. |
Returns
Nothing. The rule stays in force for the whole run.
Remarks
- Call it once, at the top level of the script, with fixed values. The rule applies from the first bar, so placing it inside an if block does not delay it.
- A script can set each risk rule once. A later call to the same function replaces the earlier one.
Example
//@version=6
strategy("Drawdown cap", overlay = true, initial_capital = 10000)
strategy.risk.max_drawdown(15, strategy.percent_of_equity, "Drawdown limit reached")
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
plot(ta.sma(close, 30), "SMA 30", color.orange)See also
strategy.risk.max_intraday_lossstrategy.risk.max_cons_loss_daysstrategy.max_drawdownstrategy.percent_of_equitystrategy.cash
Runs on Sidechair