Backtrader Community

    • 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/

    Group orders with transmit but with 2 orders instead of 3?

    General Code/Help
    3
    5
    351
    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.
    • B
      booboothefool last edited by

      So this will work:

      self.E1 = self.buy(price=entry_price, size=size, exectype=bt.Order.Stop, transmit=False)
      self.SL1 = self.sell(price=stoploss_price, size=size, exectype=bt.Order.Stop, transmit=False, parent=self.E1)
      self.TP1 = self.sell(price=TP1_price, size=size, exectype=bt.Order.Limit, transmit=True, parent=self.E1)
      

      This will not:

      self.E1 = self.buy(price=entry_price, size=size, exectype=bt.Order.Stop, transmit=False)
      self.SL1 = self.sell(price=stoploss_price, size=size, exectype=bt.Order.Stop, transmit=True, parent=self.E1)
      

      It gives an error saying self.SL1 = self.sell(price=stoploss_price, size=size, exectype=bt.Order.Stop, transmit=True) doesn't work because it is unpacked into parent, stop so it's expecting like parent, stop = self.sell(price=stoploss_price, size=size, exectype=bt.Order.Stop, transmit=True, parent=self.E1) for some reason, which is not the case if you had 3 like TP1.

      But I just want to group the entry with a stop, without take profit. How should this be done?

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        @booboothefool said in Group orders with transmit but with 2 orders instead of 3?:

        elf.E1 = self.buy(price=entry_price, size=size, exectype=bt.Order.Stop, transmit=False)
        self.SL1 = self.sell(price=stoploss_price, size=size, exectype=bt.Order.Stop, transmit=True, parent=self.E1)

        I'm not sure why you are experiencing an error. I've copied your code and working for me.

        RunBacktest.com

        1 Reply Last reply Reply Quote 1
        • B
          booboothefool last edited by

          Oh, forgot to mention. It works perfectly fine in backtesting but craps out live.

          1 Reply Last reply Reply Quote 1
          • ?
            A Former User last edited by

            This would create a one sided bracket order, while bt expects both sides. Not really sure why it worked for @run-out but bt broker will pop both sides and fail because only one order is available.

            1 Reply Last reply Reply Quote 0
            • ?
              A Former User last edited by

              I fixed the issue with oanda broker. It will now assume, there is no stopside

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