Sidechair

strategy.opentrades.entry_price()

Browse the reference

The price at which an open trade was entered.

Try it in the editor

strategy.opentrades.entry_price(trade_num) is the fill price of the entry that opened this trade, not an average. With pyramiding, each open trade keeps its own entry price, while strategy.position_avg_price gives the size-weighted average of all of them.

Compare it with close for the distance the trade has moved, or use it to place stops relative to the entry.

Syntax

Pine Script
strategy.opentrades.entry_price(trade_num: series int) -> series float

Arguments

NameTypeDefaultDescription
trade_numseries intrequiredZero-based index of the open trade. 0 is the oldest open entry, the one a FIFO exit closes first, and strategy.opentrades - 1 is the newest.

Returns

series float: The price the open trade's entry order filled at, slippage included. na when the trade does not exist.

Remarks

  • Returns na when trade_num is negative or is not below strategy.opentrades, so guard every call with the open-trade count.

Example

Pine ScriptStop line under the first entryOpen in editor
//@version=6
strategy("Entry stop", 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")
stop = strategy.opentrades > 0 ? strategy.opentrades.entry_price(0) * 0.98 : na
plot(stop, "Stop, -2%", color.red, style = plot.style_linebr)

See also

Runs on Sidechair