strategy.opentrades.entry_bar_index() - Pine Script Function
strategy.opentrades.entry_bar_index()
Section titled “strategy.opentrades.entry_bar_index()”Overview
Section titled “Overview”Returns the bar_index of the open trade’s entry.
Syntax
Section titled “Syntax”strategy.opentrades.entry_bar_index(trade_num) → series intParameters
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”// Wait 10 bars and then close the position.//@version=6strategy("`strategy.opentrades.entry_bar_index` Example")barsSinceLastEntry() => strategy.opentrades > 0 ? bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades - 1) : na// Enter a long positionif there are no open positions.if strategy.opentrades == 0strategy.entry("Long", strategy.long)// Close the long position after 10 bars.if barsSinceLastEntry() >= 10strategy.close("Long")