The price at which a closed trade was exited.
strategy.closedtrades.exit_price(trade_num) is the fill price of the order that closed the trade. A stop or limit exit fills at its level, or at the open of the bar when price gapped through it; a market exit fills at the next open.
Subtract strategy.closedtrades.entry_price for a long (the other way round for a short) to get the points the trade captured before commission.
Syntax
strategy.closedtrades.exit_price(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 price the trade's closing order filled at, slippage included. 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).
Example
//@version=6
strategy("Points captured", 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
dir = n >= 0 ? math.sign(strategy.closedtrades.size(n)) : na
pts = n >= 0 ? dir * (strategy.closedtrades.exit_price(n) - strategy.closedtrades.entry_price(n)) : na
plot(pts, "Points", color.teal, style = plot.style_columns)See also
strategy.closedtrades.entry_pricestrategy.closedtrades.exit_bar_indexstrategy.closedtrades.profitstrategy.exit
Runs on Sidechair