strategy.opentrades.commission() - Pine Script Function
strategy.opentrades.commission()
Section titled “strategy.opentrades.commission()”Overview
Section titled “Overview”Returns the sum of entry and exit fees paid in the open trade, expressed in strategy.account_currency.
Syntax
Section titled “Syntax”strategy.opentrades.commission(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 gross profit or lossfor the current open position.//@version=6strategy("`strategy.opentrades.commission` Example", commission_type = strategy.commission.percent, commission_value = 0.1)// Strategy calls to enter long trades every 15 bars and exit long trades every 20 bars.if bar_index % 15 == 0strategy.entry("Long", strategy.long)if bar_index % 20 == 0strategy.close("Long")// Calculate gross profit or lossfor open positionsonly.tradeOpenGrossPL() => sumOpenGrossPL = 0.0for tradeNo = 0 to strategy.opentrades - 1 sumOpenGrossPL +=strategy.opentrades.profit(tradeNo) - strategy.opentrades.commission(tradeNo)result = sumOpenGrossPLplot(tradeOpenGrossPL())