strategy.closedtrades.exit_price() - Pine Script Function
strategy.closedtrades.exit_price()
Section titled “strategy.closedtrades.exit_price()”Overview
Section titled “Overview”Returns the price of the closed trade’s exit.
Syntax
Section titled “Syntax”strategy.closedtrades.exit_price(trade_num) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| trade_num | series int | The trade number of the closed trade. The number of the first trade is zero. |
Examples
Section titled “Examples”Example 1
Section titled “Example 1”// Calculates the average profit percentagefor all closed trades.//@version=6strategy("strategy.closedtrades.exit_price Example 2")// Strategy calls to create single short and long trades.if bar_index == last_bar_index - 15strategy.entry("Long Entry", strategy.long)elseif bar_index == last_bar_index - 10strategy.close("Long Entry")strategy.entry("Short", strategy.short)elseif bar_index == last_bar_index - 5strategy.close("Short")// Calculate profitfor both closed trades.profitPct = 0.0for tradeNo = 0 to strategy.closedtrades - 1 entryP =strategy.closedtrades.entry_price(tradeNo)exitP = strategy.closedtrades.exit_price(tradeNo)profitPct += (exitP - entryP) / entryP * strategy.closedtrades.size(tradeNo) * 100// Calculate average profit percentfor both closed trades.avgProfitPct =nz(profitPct / strategy.closedtrades)plot(avgProfitPct)