Skip to content
Algo Trade Analytics Docs

strategy.closedtrades.entry_price() - Pine Script Function

Returns the price of the closed trade’s entry.

strategy.closedtrades.entry_price(trade_num) → series float
NameTypeDescription
trade_numseries intThe trade number of the closed trade. The number of the first trade is zero.
// Calculates the average profit percentage
for all closed trades.//@version=6
strategy("strategy.closedtrades.entry_price Example 2")// Strategy calls to create single short and long trades
if bar_index == last_bar_index - 15
strategy.entry("Long Entry", strategy.long)
else
if bar_index == last_bar_index - 10
strategy.close("Long Entry")
strategy.entry("Short", strategy.short)
else
if bar_index == last_bar_index - 5
strategy.close("Short")// Calculate profit
for both closed trades.profitPct = 0.0
for tradeNo = 0 to strategy.closedtrades - 1 entryP =
strategy.closedtrades.entry_price(tradeNo)
exitP = strategy.closedtrades.exit_price(tradeNo)
profitPct += (exitP - entryP) / entryP * strategy.closedtrades.size(tradeNo) * 100// Calculate average profit percent
for both closed trades.avgProfitPct =
nz(profitPct / strategy.closedtrades)
plot(avgProfitPct)