Open trade with no commission
-
Hi all.
Just a real quick one.
I have set my broker commission as follows (for example) - aim was to have a fixed commission for each trade:
cerebro.broker.setcommission(commission=0.015, leverage=100, commtype=bt.CommInfoBase.COMM_FIXED)
I successfully open a buy_bracket order as follows:
self.buy_bracket(tradeid = 1, exectype = bt.Order.Market, price = action_info['price'], size = 0.01, limitprice = action_info['take_profit'], stopprice = action_info['stop_loss'])
This order will obviously be immediately filled at Market price as I have selected
bt.Order.Market
and the broker commission will be assigned to it.My question relates to modifying an existing order. As
Backtrader
does not have that built-in yet, I close my existing order and open a new one with the modifiedstoploss
and/ortakeprofit
.My logic goes something like this for a trade with
tradeid = 1
:self.close(tradeid = 1, size = 0.01) self.buy_bracket(tradeid = 1, exectype = bt.Order.Market, price = action_info['price'], size = 0.01, limitprice = action_info['new_take_profit'], stopprice = action_info['new_stop_loss'])
I therefore will be charged with another commission when this trade is modified. Is there a way to open a
buy_bracket
order withcommission = 0
even though I have set it insetcommission
?I was thinking of doing the followingf, but it doesn't work:
self.close(tradeid = 1, size = 0.01) self.buy_bracket(tradeid = 1, exectype = bt.Order.Market, price = action_info['price'], size = 0.01, limitprice = action_info['new_take_profit'], stopprice = action_info['new_stop_loss'], commission = 0.0)
Thanks for your time. Hope this is clear enough.
Tagging @backtrader @EMR as they pretty active and helpful
-
and @run-out Many thanks guys
-
Hi all.
Managed to get this right by redefining the broker commission each time I want to modify my order (meaning I want to close and reopen an order with different parameters with zero commission).
The procedure I followed was to refine the
setcommission
as follows:self.broker.setcommission(commission=0, leverage=self.leverage, commtype=bt.CommInfoBase.COMM_FIXED) self.close(tradeid = 1, size = 0.01) self.buy_bracket(tradeid = 1, exectype = bt.Order.Market, price = action_info['price'], size = 0.01, limitprice = action_info['new_take_profit'], stopprice = action_info['new_stop_loss'], commission = 0.0)
NB! Just remember to reset your commission scheme before opening real market orders again.
Additional checks:
- The way I checked whether this works is by outputting the comminfo after setting the commission to my desired value.
- this can be done as follows (in python):
self.broker.setcommission(commission=self.commission, leverage=self.leverage, commtype=bt.CommInfoBase.COMM_FIXED) print(self.broker.comminfo[None].params.__dict__) # should print your broker's commission fee self.broker.setcommission(commission=0, leverage=self.leverage, commtype=bt.CommInfoBase.COMM_FIXED) print(self.broker.comminfo[None].params.__dict__) # should print zero commission fee
Hope this helps. Just tag me if you have any further questions or alternative tips