I am wondering if it is possible to change the commission during "next()" iterations?
I have cases where if certain conditions are met, I want to go "leveraged long with margin" (eg. 2x leverage)... but if these conditions are not met, I do not want any leverage, just normal buy and sell trades (without any margin requirements).
I tried using "self.broker.addcommissioninfo" at the start of each "next()" and adding a margin comminfo where appropriate, but I do not believe this is the correct way to do it.
Would love to know if this is possible at all? I am using my own custom comminfo if that matters (code below).
params = (
def _getcommission(self, size, price, pseudoexec):
commvalue = abs(size) * price * self.p.commission # %based commission value
commvalue = max(self.p.min_fee,commvalue) # choose the greater of $min_fee and percentage calculated
Desired commission info to "use" when in normal conditions:
comminfo = CommInfo_Custom(commission=v.comm_pct
Desired commission info to "use" when in "leverage" conditions:
comminfo_leveraged_long = CommInfo_Custom(commission=v.comm_pct
,automargin=0.5 #must hold 0.5*price to hold a margin position
,leverage=2.0 #Amount of leverage for the asset with regards to the needed cash
,mult=2.0) #multiplier applied to the asset for value/profit
Thanks so much!!