strategy.opentrades.entry_price() - Pine Script Function
strategy.opentrades.entry_price()
Section titled “strategy.opentrades.entry_price()”Overview
Section titled “Overview”Returns the price of the open trade’s entry.
Syntax
Section titled “Syntax”strategy.opentrades.entry_price(trade_num) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| trade_num | series int | The trade number of the open trade. The number of the first trade is zero. |
Examples
Section titled “Examples”Example 1
Section titled “Example 1”// Calculates the average pricefor the open position.//@version=6strategy("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 == 0strategy.entry("Long", strategy.long)if bar_index % 20 == 0strategy.close("Long")// Calculates the average pricefor the openposition.avgOpenPositionPrice() => sumOpenPositionPrice = 0.0for 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())