Sidechair

strategy.closedtrades.entry_price()

Browse the reference

The price at which a closed trade was entered.

Try it in the editor

strategy.closedtrades.entry_price(trade_num) is the fill price of the entry order, in the symbol's price units. A market entry fills at the open of the bar after the order was sent, plus any slippage set in strategy(); with process_orders_on_close = true it fills at the close of the bar that sent it.

Pair it with strategy.closedtrades.exit_price to draw each trade on the chart or to measure how far price travelled.

Syntax

Pine Script
strategy.closedtrades.entry_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 entry 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 ScriptMark the last trade's entryOpen in editor
//@version=6
strategy("Last entry", overlay = true)
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")
if barstate.islast and strategy.closedtrades > 0
    n = strategy.closedtrades - 1
    line.new(strategy.closedtrades.entry_bar_index(n), strategy.closedtrades.entry_price(n), bar_index, strategy.closedtrades.entry_price(n), color = color.blue)

See also

Runs on Sidechair