The id of the order that opened a closed trade, as passed to strategy.entry.
strategy.closedtrades.entry_id(trade_num) returns the text you passed as the first argument of strategy.entry or strategy.order. It lets you group results by setup when a script trades several entries under different ids.
Syntax
strategy.closedtrades.entry_id(trade_num: series int) -> series stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| trade_num | series int | required | Zero-based index of the closed trade. 0 is the first trade the strategy closed and strategy.closedtrades - 1 is the most recent. |
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, is not below
strategy.closedtrades, or points at a trade that has dropped out of the history (seestrategy.closedtrades.first_index). - Ids are case sensitive. Compare with == and the exact text you used when entering.
Example
//@version=6
strategy("Profit by id", overlay = false)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
longProfit = 0.0
for i = strategy.closedtrades.first_index to strategy.closedtrades - 1
if strategy.closedtrades.entry_id(i) == "Long"
longProfit += strategy.closedtrades.profit(i)
plot(longProfit, "Profit of 'Long' entries", color.green)See also
strategy.closedtrades.exit_idstrategy.closedtrades.entry_commentstrategy.opentrades.entry_idstrategy.entry
Runs on Sidechair