Profit or loss of a closed trade as a percentage of the value it was entered at.
strategy.closedtrades.profit_percent(trade_num) divides the trade's net profit by its entry value (entry price times size times the point value) and multiplies by 100. A long that gained 2% returns 2; a short that lost 1.5% returns -1.5.
Because it is relative to the trade's own size, it lets you compare trades taken with different quantities.
Syntax
strategy.closedtrades.profit_percent(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 trade's net profit as a percentage of its entry value; negative for a loss. 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 figure is net of commission, the same as
strategy.closedtrades.profit, so a trade that moved a little in your favour can still be negative.
Example
//@version=6
strategy("Average trade, %", 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")
total = 0.0
for i = strategy.closedtrades.first_index to strategy.closedtrades - 1
total += strategy.closedtrades.profit_percent(i)
avg = strategy.closedtrades > 0 ? total / strategy.closedtrades : na
plot(avg, "Average trade, %", color.blue)
hline(0)See also
strategy.closedtrades.profitstrategy.closedtrades.max_runup_percentstrategy.closedtrades.max_drawdown_percentstrategy.avg_trade_percent
Runs on Sidechair