pine script - Is there a way to incorporate dynamic commission fees in the TradingView Strategy Tester? - Stack Overflow

时间: 2025-01-06 admin 业界

I am trying to incorporate a dynamic commission fee in the strategy tester. I am aware the PineScript strategy function provides some functionality to specify commission fees, for example

strategy(..., commission_type=strategymission.cash_per_contract, commission_value=0.005)

This however is a bit restrictive in terms of setting a min commission fee.

The outcome I am looking for is being able to set a min commission value, for example:

  • Flat fee per share: $0.005
  • Minimum fee per trade: $1.00

If flat fee * quantity is less than $1, use $1.

I have tried calculating the fee and setting it after strategy initialization, this however does not work since it does not seem the strategy instance provides an attribute for such a case:

if (strategy.position_size < 0)  // Short position
    ....
    ....
    ....
    if (....)
        // Perhaps set fee here in some way
        strategy.close("Short")

Is the outcome I am trying to achieve possible in the trading view strategy tester?