Sidechair

strategy.opentrades.commission()

Browse the reference

The commission an open trade has paid so far, which is the fee charged on its entry.

Try it in the editor

strategy.opentrades.commission(trade_num) returns the fee charged when the trade was entered. The exit fee is not known until the trade closes, and then it joins the total shown by strategy.closedtrades.commission.

The fee follows commission_type and commission_value in the strategy() header.

Syntax

Pine Script
strategy.opentrades.commission(trade_num: series int) -> series float

Arguments

NameTypeDefaultDescription
trade_numseries intrequiredZero-based index of the open trade. 0 is the oldest open entry, the one a FIFO exit closes first, and strategy.opentrades - 1 is the newest.

Returns

series float: The commission paid so far on the open trade, which is its entry commission, in the account currency. na when the trade does not exist.

Remarks

  • Returns na when trade_num is negative or is not below strategy.opentrades, so guard every call with the open-trade count.

Example

Pine ScriptFees tied up in open tradesOpen in editor
//@version=6
strategy("Open fees", overlay = false, pyramiding = 3, commission_type = strategy.commission.percent, commission_value = 0.1)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if fast > slow and bar_index % 20 == 0
    strategy.entry("Layer " + str.tostring(strategy.opentrades + 1), strategy.long)
if ta.crossunder(fast, slow)
    strategy.close_all()
fees = 0.0
for i = 0 to strategy.opentrades - 1
    fees += strategy.opentrades.commission(i)
plot(fees, "Commission on open trades", color.red)

See also

Runs on Sidechair