strategy.closedtrades.entry_id() - Pine Script Function
strategy.closedtrades.entry_id()
Section titled “strategy.closedtrades.entry_id()”Overview
Section titled “Overview”Returns the id of the closed trade’s entry.
Syntax
Section titled “Syntax”strategy.closedtrades.entry_id(trade_num) → series stringParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| trade_num | series int | The trade number of the closed trade. The number of the first trade is zero. |
Returns
Section titled “Returns”Returns the id of the closed trade’s entry.
Remarks
Section titled “Remarks”- The function returns na if trade_num is not in the range: 0 to strategy.closedtrades-1.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6strategy("strategy.closedtrades.entry_id Example", overlay = true)// Enter a short position and close at the previous to last bar.if bar_index == 1strategy.entry("Short at bar #" + str.tostring(bar_index), strategy.short)if bar_index == last_bar_index - 2strategy.close_all()// Display ID of the last entry position.if barstate.islastconfirmedhistorylabel.new(last_bar_index, high, "Last Entry ID is: " + strategy.closedtrades.entry_id(strategy.closedtrades - 1))