Sidechair

strategy.closedtrades.entry_id()

Browse the reference

The id of the order that opened a closed trade, as passed to strategy.entry.

Try it in the editor

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

Pine Script
strategy.closedtrades.entry_id(trade_num: series int) -> series string

Arguments

NameTypeDefaultDescription
trade_numseries intrequiredZero-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 (see strategy.closedtrades.first_index).
  • Ids are case sensitive. Compare with == and the exact text you used when entering.

Example

Pine ScriptProfit by setup idOpen in editor
//@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

Runs on Sidechair