Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Open trade with no commission

    General Discussion
    1
    3
    36
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Pierre Cilliers 0
      Pierre Cilliers 0 last edited by

      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 modified stoploss and/or takeprofit.

      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 with commission = 0 even though I have set it in setcommission?

      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

      1 Reply Last reply Reply Quote 0
      • Pierre Cilliers 0
        Pierre Cilliers 0 last edited by

        and @run-out Many thanks guys

        1 Reply Last reply Reply Quote 0
        • Pierre Cilliers 0
          Pierre Cilliers 0 last edited by

          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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors