The best unrealised profit a closed trade reached while it was open, in the account currency.
strategy.closedtrades.max_runup(trade_num) is the peak profit the trade showed at any time between entry and exit, measured against the entry price and using each bar's high and low rather than only closes.
Comparing it with the realised profit tells you how much a trade gave back before it closed, which is a direct way to judge your exit rules.
Syntax
strategy.closedtrades.max_runup(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 largest unrealised gain the trade showed while open, in the account currency. 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). - The run-up is never below 0 for a trade that closed at a profit.
Example
//@version=6
strategy("Given back", 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")
n = strategy.closedtrades - 1
gave = n >= 0 ? strategy.closedtrades.max_runup(n) - strategy.closedtrades.profit(n) : na
plot(gave, "Peak minus final profit", color.orange, style = plot.style_columns)See also
strategy.closedtrades.max_runup_percentstrategy.closedtrades.max_drawdownstrategy.closedtrades.profitstrategy.max_runup
Runs on Sidechair