The best unrealised profit an open trade has reached so far, in the account currency.
strategy.opentrades.max_runup(trade_num) is the highest profit the trade has shown since its entry, measured against the entry price and using each bar's high and low. It can only grow while the trade stays open.
Compare it with strategy.opentrades.profit to see how much of the peak you have given back, the basis of a trailing exit.
Syntax
strategy.opentrades.max_runup(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 best unrealised gain 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.
Example
//@version=6
strategy("Peak giveback", 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")
back = strategy.opentrades > 0 ? strategy.opentrades.max_runup(0) - strategy.opentrades.profit(0) : na
plot(back, "Given back", color.orange, style = plot.style_linebr)See also
strategy.opentrades.max_runup_percentstrategy.opentrades.max_drawdownstrategy.closedtrades.max_runupstrategy.opentrades.profit
Runs on Sidechair