The id of the order that opened an open trade, as passed to strategy.entry.
strategy.opentrades.entry_id(trade_num) returns the id used when the trade was entered. Because every filled entry order is its own trade, the ids of a pyramided position are listed separately, so you can find and manage one layer.
Syntax
strategy.opentrades.entry_id(trade_num: series int) -> series stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| trade_num | series int | required | Zero-based index of the open trade. 0 is the oldest open entry, the one a FIFO exit closes first, and strategy.opentrades - 1 is the newest. |
Returns
series string: The id string given to the entry order. na when the trade does not exist.
Remarks
- Returns na when trade_num is negative or is not below
strategy.opentrades, so guard every call with the open-trade count. - Ids are case sensitive.
Example
//@version=6
strategy("Layer ids", overlay = true, pyramiding = 3)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if fast > slow and bar_index % 20 == 0
strategy.entry("Layer " + str.tostring(strategy.opentrades + 1), strategy.long)
if ta.crossunder(fast, slow)
strategy.close_all()
if barstate.islast and strategy.opentrades > 0
label.new(bar_index, low, strategy.opentrades.entry_id(strategy.opentrades - 1), style = label.style_label_up)See also
Runs on Sidechair