Sidechair

strategy.closedtrades.max_drawdown_percent()

Browse the reference

The worst unrealised loss a closed trade suffered, as a percentage of its entry value.

Try it in the editor

strategy.closedtrades.max_drawdown_percent(trade_num) is the trade's worst intrabar loss divided by its entry value, times 100.

Use it to pick a stop distance from history: if most winning trades never dipped more than 1%, a 3% stop leaves them room while still capping the losers.

Syntax

Pine Script
strategy.closedtrades.max_drawdown_percent(trade_num: series int) -> series float

Arguments

NameTypeDefaultDescription
trade_numseries intrequiredZero-based index of the closed trade. 0 is the first trade the strategy closed and strategy.closedtrades - 1 is the most recent.

Returns

series float: The deepest unrealised loss as a percentage of the trade's entry value. na when the trade does not exist.

Remarks

Example

Pine ScriptAverage dip per tradeOpen in editor
//@version=6
strategy("Average drawdown, %", overlay = false)
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")
sum = 0.0
for i = strategy.closedtrades.first_index to strategy.closedtrades - 1
    sum += math.abs(strategy.closedtrades.max_drawdown_percent(i))
plot(strategy.closedtrades > 0 ? sum / strategy.closedtrades : na, "Average dip, %", color.red)

See also

Runs on Sidechair