Sidechair

strategy.closedtrades.max_runup_percent()

Browse the reference

The best unrealised profit a closed trade reached, as a percentage of its entry value.

Try it in the editor

strategy.closedtrades.max_runup_percent(trade_num) is the peak profit of the trade divided by its entry value, times 100. It uses the same intrabar highs and lows as strategy.closedtrades.max_runup.

Being relative to the trade's size, it is the version to average across trades or to compare with profit_percent.

Syntax

Pine Script
strategy.closedtrades.max_runup_percent(trade_num: series int) -> series float

Arguments

NameTypeDefaultDescription
trade_numseries intrequiredZero-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 as a percentage of the trade's entry value. 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 (see strategy.closedtrades.first_index).

Example

Pine ScriptAverage peak gain per tradeOpen in editor
//@version=6
strategy("Average run-up, %", 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")
sum = 0.0
for i = strategy.closedtrades.first_index to strategy.closedtrades - 1
    sum += strategy.closedtrades.max_runup_percent(i)
plot(strategy.closedtrades > 0 ? sum / strategy.closedtrades : na, "Average run-up, %", color.teal)

See also

Runs on Sidechair