Functions
strategy.closedtrades_entry_id()
For the closed trade number `trade_num`, returns the `id` of the entry order that opened the trade. Trades are numbered from 0 in the order they were closed, so the most recent is `strategy.closedtrades - 1`.
Syntax
strategy.closedtrades_entry_id(series int trade_num) → series string
Arguments
trade_num required series int Return Type
series string Example
//@lipi=2
strategy("strategy.closedtrades_entry_id Example", overlay=true, initial_capital=10000, default_qty_type=strategy.fixed, default_qty_value=1)
if talib.crossover(close, talib.sma(close, 20)) {
strategy.entry("Long", strategy.long)
}
if talib.crossunder(close, talib.sma(close, 20)) {
strategy.close("Long")
}
if barstate.islast and strategy.closedtrades > 0 {
label.new(bar_index, high, text="Last closed trade: " + strategy.closedtrades_entry_id(strategy.closedtrades - 1))
}