Sidechair

strategy.max_drawdown

Browse the reference

The largest peak-to-trough fall in equity so far, in the account currency.

Try it in the editor

strategy.max_drawdown is a series float: the biggest drop from an equity high to the following low since the first bar, in money. It only grows. A strategy that has never fallen below a previous equity high reads 0.

Type

series float

Remarks

  • The drawdown is measured on equity, so open losses count before the trade closes.
  • The sign is positive for a drop; compare absolute values when you test thresholds.

Example

Pine ScriptHalt after a drawdown of 20 percent of capitalOpen in editor
//@version=6
strategy("Drawdown halt", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
halted = strategy.max_drawdown > strategy.initial_capital * 0.2
if ta.crossover(ta.sma(close, 10), ta.sma(close, 30)) and not halted
    strategy.entry("Long", strategy.long)
if ta.crossunder(ta.sma(close, 10), ta.sma(close, 30)) or halted
    strategy.close_all()
plot(strategy.max_drawdown, "Max drawdown", color.red)

See also

Runs on Sidechair