Sidechair

strategy.opentrades.entry_comment()

Browse the reference

The comment attached to the order that opened an open trade.

Try it in the editor

strategy.opentrades.entry_comment(trade_num) returns the comment argument of the entry order that created this trade.

Put the reason for the entry in the comment and show it on the chart while the trade is open.

Syntax

Pine Script
strategy.opentrades.entry_comment(trade_num: series int) -> series string

Arguments

NameTypeDefaultDescription
trade_numseries intrequiredZero-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 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 or is not below strategy.opentrades, so guard every call with the open-trade count.

Example

Pine ScriptShow the open trade's reasonOpen in editor
//@version=6
strategy("Open reason", 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.opentrades > 0
    label.new(bar_index, high, strategy.opentrades.entry_comment(0))

See also

Runs on Sidechair