The price at which an open trade was entered.
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
strategy.opentrades.entry_price(trade_num: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| trade_num | series int | required | Zero-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
//@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
strategy.closedtrades.entry_pricestrategy.position_avg_pricestrategy.opentrades.sizestrategy.opentrades
Runs on Sidechair