strategy.opentrades.entry_id() - Pine Script Function
strategy.opentrades.entry_id()
Section titled “strategy.opentrades.entry_id()”Overview
Section titled “Overview”Returns the id of the open trade’s entry.
Syntax
Section titled “Syntax”strategy.opentrades.entry_id(trade_num) → series stringParameters
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. |
Returns
Section titled “Returns”Returns the id of the open trade’s entry.
Remarks
Section titled “Remarks”- The function returns na if trade_num is not in the range: 0 to strategy.opentrades-1.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6strategy("`strategy.opentrades.entry_id` Example", overlay = true)// We enter a long position when 14 period sma crosses over 28 period sma.// We enter a short position when 14 period sma crosses under 28 period sma.longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))// Strategy calls to enter a long or short position when the corresponding condition is met.if longConditionstrategy.entry("Long entry at bar #" + str.tostring(bar_index), strategy.long)if shortConditionstrategy.entry("Short entry at bar #" + str.tostring(bar_index), strategy.short)// Display ID of the latest open position.if barstate.islastconfirmedhistorylabel.new(bar_index, high + (2 * ta.tr), "Last opened position is \n " + strategy.opentrades.entry_id(strategy.opentrades - 1))