The worst unrealised loss an open trade has suffered so far, as a percentage of its entry value.
strategy.opentrades.max_drawdown_percent(trade_num) is the trade's worst intrabar loss since entry divided by its entry value, times 100.
A rule such as "exit once the trade has dipped more than 4%" reads this value, because it keeps the dip even after price recovers.
Syntax
strategy.opentrades.max_drawdown_percent(trade_num: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| trade_num | series int | required | Zero-based index of the open trade. 0 is the oldest open entry, the one a FIFO exit closes first, and strategy.opentrades - 1 is the newest. |
Returns
series float: The deepest unrealised loss so far as a percentage of the trade's entry value. na when the trade does not exist.
Remarks
- Returns na when trade_num is negative or is not below
strategy.opentrades, so guard every call with the open-trade count.
Example
//@version=6
strategy("Dip exit", overlay = true)
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")
if strategy.opentrades > 0 and math.abs(strategy.opentrades.max_drawdown_percent(0)) > 4
strategy.close("Long", comment = "dip exit")See also
strategy.opentrades.max_drawdownstrategy.opentrades.max_runup_percentstrategy.closedtrades.max_drawdown_percentstrategy.opentrades.profit_percent
Runs on Sidechair