Sidechair

strategy.risk.max_drawdown()

Browse the reference

Stops the strategy when its equity falls a set amount below its highest value.

Try it in the editor

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

Pine Script
strategy.risk.max_drawdown(value: simple int/float, type: simple string, alert_message: simple string (optional)) -> void

Arguments

NameTypeDefaultDescription
valuesimple int/floatrequiredThe largest drawdown allowed, in the unit chosen by type. Must be positive.
typesimple stringrequiredHow value is read: strategy.percent_of_equity for a percentage of equity, or strategy.cash for an amount in the account currency.
alert_messagesimple stringnaText 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

Pine ScriptStop at 15% drawdownOpen in editor
//@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

Runs on Sidechair