strategy.opentrades.profit() - Pine Script Function
strategy.opentrades.profit()
Section titled “strategy.opentrades.profit()”Overview
Section titled “Overview”Returns the profit/loss of the open trade, expressed in strategy.account_currency. Losses are expressed as negative values.
Syntax
Section titled “Syntax”strategy.opentrades.profit(trade_num) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| trade_num | series int | The trade number of the open trade. The number of the first trade is zero. |
Examples
Section titled “Examples”Example 1
Section titled “Example 1”// Calculates the profitfor all open trades.//@version=6strategy("`strategy.opentrades.profit` Example 2", pyramiding = 5)// Strategy calls to enter 5 long positions every 2 bars.if bar_index % 2 == 0strategy.entry("Long", strategy.long, qty = 5)// Calculate open profit or lossfor the openpositions.tradeOpenPL() => sumProfit = 0.0for tradeNo = 0 to strategy.opentrades - 1 sumProfit +=strategy.opentrades.profit(tradeNo) result = sumProfitplot(tradeOpenPL(), "Profit of all open trades")