The worst unrealised loss an open trade has suffered so far, in the account currency.
strategy.opentrades.max_drawdown(trade_num) is the lowest profit the trade has shown since entry, measured against the entry price and using each bar's high and low. It can only deepen while the trade stays open.
It tells you how far the trade has already gone against you, even if it has since recovered.
Syntax
strategy.opentrades.max_drawdown(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 the open trade has shown so far, in the account currency. 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. - Use
math.abswhen comparing values from different trades, so the result does not depend on the sign.
Example
//@version=6
strategy("Open heat", 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")
heat = strategy.opentrades > 0 ? math.abs(strategy.opentrades.max_drawdown(0)) : na
plot(heat, "Worst dip so far", color.red, style = plot.style_linebr)See also
strategy.opentrades.max_drawdown_percentstrategy.opentrades.max_runupstrategy.closedtrades.max_drawdownstrategy.opentrades.profit
Runs on Sidechair