The best unrealised profit an open trade has reached so far, as a percentage of its entry value.
strategy.opentrades.max_runup_percent(trade_num) is the peak profit since entry divided by the trade's entry value, times 100.
Use it for size-independent rules, such as moving a stop to breakeven once the peak gain passes a set percentage.
Syntax
strategy.opentrades.max_runup_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 best unrealised gain 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("Breakeven rule", 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")
armed = strategy.opentrades > 0 and strategy.opentrades.max_runup_percent(0) >= 3
be = armed ? strategy.opentrades.entry_price(0) : na
plot(be, "Breakeven stop", color.blue, style = plot.style_linebr)See also
strategy.opentrades.max_runupstrategy.opentrades.max_drawdown_percentstrategy.closedtrades.max_runup_percentstrategy.opentrades.profit_percent
Runs on Sidechair