The worst unrealised loss a closed trade suffered, as a percentage of its entry value.
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
strategy.closedtrades.max_drawdown_percent(trade_num: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| trade_num | series int | required | Zero-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
- Returns na when trade_num is negative, is not below
strategy.closedtrades, or points at a trade that has dropped out of the history (seestrategy.closedtrades.first_index). - Apply
math.absbefore comparing values from different trades, for the same reason asstrategy.closedtrades.max_drawdown.
Example
//@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
strategy.closedtrades.max_drawdownstrategy.closedtrades.max_runup_percentstrategy.closedtrades.profit_percentstrategy.max_drawdown_percent
Runs on Sidechair