Sidechair

strategy.closedtrades.entry_comment()

Browse the reference

The comment attached to the order that opened a closed trade.

Try it in the editor

strategy.closedtrades.entry_comment(trade_num) returns the comment argument of the entry order. Use it to record why you entered, for example the signal name or the value of an indicator, and read it back when you analyse trades.

Syntax

Pine Script
strategy.closedtrades.entry_comment(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 comment text given to the entry order, an empty string when none was given. 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).

Example

Pine ScriptShow why the last trade beganOpen in editor
//@version=6
strategy("Entry comment", overlay = true)
if ta.crossover(ta.sma(close, 10), ta.sma(close, 30))
    strategy.entry("Long", strategy.long, comment = "SMA cross")
if ta.crossunder(ta.sma(close, 10), ta.sma(close, 30))
    strategy.close("Long")
if barstate.islast and strategy.closedtrades > 0
    label.new(bar_index, high, strategy.closedtrades.entry_comment(strategy.closedtrades - 1))

See also

Runs on Sidechair