Sidechair

strategy.closedtrades.exit_comment()

Browse the reference

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

Try it in the editor

strategy.closedtrades.exit_comment(trade_num) returns the comment argument of the order that closed the trade. Give your exits distinct comments such as "target" or "time stop" and you can tally how trades ended.

Syntax

Pine Script
strategy.closedtrades.exit_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 closing 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 ScriptCount target exitsOpen in editor
//@version=6
strategy("Target exits", overlay = false)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)
    strategy.exit("Exit", "Long", limit = close * 1.02, comment = "target")
hits = 0
for i = strategy.closedtrades.first_index to strategy.closedtrades - 1
    if strategy.closedtrades.exit_comment(i) == "target"
        hits += 1
plot(hits, "Exits with comment 'target'", color.green)

See also

Runs on Sidechair