strategy.closedtrades.exit_comment() - Pine Script Function
strategy.closedtrades.exit_comment()
Section titled “strategy.closedtrades.exit_comment()”Overview
Section titled “Overview”Returns the comment message of the closed trade’s exit, or na if there is no entry with this trade_num.
Syntax
Section titled “Syntax”strategy.closedtrades.exit_comment(trade_num) → series stringParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| trade_num | series int | The trade number of the closed trade. The number of the first trade is zero. |
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6strategy("`strategy.closedtrades.exit_comment()` Example", overlay = true)longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))if (longCondition)strategy.entry("Long", strategy.long)strategy.exit("Exit", stop = open * 0.95, limit = close * 1.05, trail_points = 100, trail_offset = 0, comment_profit = "TP", comment_loss = "SL", comment_trailing = "TRAIL")exitStats() => int slCount = 0 int tpCount = 0 int trailCount = 0if strategy.closedtrades > 0for i = 0 to strategy.closedtrades - 1switch strategy.closedtrades.exit_comment(i) "TP" => tpCount += 1 "SL" => slCount += 1 "TRAIL" => trailCount += 1 [slCount, tpCount, trailCount]var testTable = table.new(position.top_right, 1, 4, color.orange, border_width = 1)if barstate.islastconfirmedhistory [slCount, tpCount, trailCount] =exitStats()table.cell(testTable, 0, 0, "Closed trades (" + str.tostring(strategy.closedtrades) +")stats:")table.cell(testTable, 0, 1, "Stop Loss: " + str.tostring(slCount))table.cell(testTable, 0, 2, "Take Profit: " + str.tostring(tpCount))table.cell(testTable, 0, 3, "Trailing Stop: " + str.tostring(trailCount))