Skip to content
Algo Trade Analytics Docs

strategy.opentrades.entry_price() - Pine Script Function

Returns the price of the open trade’s entry.

strategy.opentrades.entry_price(trade_num) → series float
NameTypeDescription
trade_numseries intThe trade number of the open trade. The number of the first trade is zero.
// Calculates the average price
for the open position.//@version=6
strategy("strategy.opentrades.entry_price Example 2", pyramiding = 2)// Strategy calls to enter long trades every 15 bars and exit long trades every 20 bars.
if bar_index % 15 == 0
strategy.entry("Long", strategy.long)
if bar_index % 20 == 0
strategy.close("Long")// Calculates the average price
for the open
position.avgOpenPositionPrice() => sumOpenPositionPrice = 0.0
for tradeNo = 0 to strategy.opentrades - 1 sumOpenPositionPrice +=
strategy.opentrades.entry_price(tradeNo) * strategy.opentrades.size(tradeNo) / strategy.position_size result = nz(sumOpenPositionPrice / strategy.opentrades)
plot(avgOpenPositionPrice())