Sidechair

strategy.closedtrades.exit_price()

Browse the reference

The price at which a closed trade was exited.

Try it in the editor

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

Pine Script
strategy.closedtrades.exit_price(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 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 (see strategy.closedtrades.first_index).

Example

Pine ScriptPoints captured by the last tradeOpen in editor
//@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

Runs on Sidechair