The commission a closed trade paid in total, on both its entry and its exit.
strategy.closedtrades.commission(trade_num) adds the commission charged when the trade opened to the commission charged when it closed. The rate comes from commission_type and commission_value in the strategy() header.
The amount is already deducted from strategy.closedtrades.profit, so add it back to see the gross result of the trade.
Syntax
strategy.closedtrades.commission(trade_num: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| trade_num | series int | required | Zero-based index of the closed trade. 0 is the first trade the strategy closed and strategy.closedtrades - 1 is the most recent. |
Returns
series float: Total commission paid on the trade, entry and exit together, in the account currency. 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 (seestrategy.closedtrades.first_index). - With commission_value = 0 the function returns 0 for every existing trade, not na.
Example
//@version=6
strategy("Fees paid", overlay = false, commission_type = strategy.commission.percent, commission_value = 0.05)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
fees = 0.0
for i = strategy.closedtrades.first_index to strategy.closedtrades - 1
fees += strategy.closedtrades.commission(i)
plot(fees, "Commission paid", color.red)See also
Runs on Sidechair