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/

    Bracker Order Questions

    General Code/Help
    2
    2
    55
    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.
    • G
      Gleetche last edited by

      Hii,

      I am trying to use bracket orders in my strategy and I can't grasp it enough to implement it.

      1. Can anyone explain to me what is the strategy of the sample code?

      2. What is this switching function in the sample code?

      if self.p.switchp1p2:
                          p1, p2 = p2, p1
                          valid1, valid2 = valid2, valid1
      
      1. What is transmit in the bracket argument?
      mainside = self.buy(price=13.50, exectype=bt.Order.Limit, transmit=False)
      
      

      https://www.backtrader.com/docu/order-creation-execution/bracket/bracket/#sample-code

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

        @gleetche

        @gleetche said in Bracker Order Questions:

        if self.p.switchp1p2:
        p1, p2 = p2, p1
        valid1, valid2 = valid2, valid1

        Ignore this for now, the docs tend to try to provide all possibilties when entering at the terminal using args.parse.

        Here is simple example of a bracket order.

        order = self.buy_bracket(
                        size=size,
                        exectype=bt.Order.Market,
                        stopprice=stop_price,
                        stopexec=bt.Order.Stop,
                        limitprice=limit_price,
                        limitexec=bt.Order.Limit,
                    )
        
        

        Order will be a list containing the three orders like:

        [entry_order, stop_order, limit_order]
        

        @gleetche said in Bracker Order Questions:

        What is transmit in the bracket argument?

        Transmit gets used when you are entering the orders separately, not like my example above. Setting transmit=False tells backtrader not to execute the first order by itself. Wait until all the orders are arranged, and then enter them (transmit) them together, so that the first order can be connected to later orders.

        RunBacktest.com

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