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/

    Order execution issue

    General Code/Help
    orders execution
    3
    7
    588
    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.
    • Anton Kozin
      Anton Kozin last edited by

      Hello everyone!

      I'm stuck with the following situation:

      I have 3 bars (OHLC):

      69/70/64/65
      65/85/60/84
      84/90/82/88

      I make a sell_bracket order at the first bar with the params:

      self.sell_bracket(
                      size=size,
                      price=65,
                      exectype=bt.Order.Market,
                      stopprice=70,
                      stopexec=bt.Order.StopLimit,
                      limitprice=None, 
                      limitexec=None
                  )
      

      Both orders from the bracket are accepted at the next bar, and the sell order is completed. But my buy order is not triggered at the second bar., and this order won't be triggered at the third bar also. This issue can be solved by adding data feed filter BarReplayer_Open, but the time for one run rises 4x. Is there any other way to make this order status Completed at the second bar?

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        I don't see any issues here. Bracket order is issued on the 1st bar, broker notified, then main order is executed on the 2nd bar, broker notified, now stop order is active starting from the 3rd bar.

        To get quicker notofications move to lower timeframe.

        Or you can try some hacks such as quicknotify (Docs - Cerebro - Reference) or cheat-on-open (Docs - Broker - Cheat-on-open).

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 0
        • Anton Kozin
          Anton Kozin last edited by

          I managed to achieve my goal by dividing bracket order and using next_open method to issue stop-loss order.

          But when you use bracket order, it's assumed that you notify broker about these 2 or 3 orders at the same time. It would be great to have something like process_orders_on_close=True, because i have my time for one run increased 2x with this solution.

          A 1 Reply Last reply Reply Quote 0
          • A
            ab_trader @Anton Kozin last edited by

            @Anton-Kozin said in Order execution issue:

            But when you use bracket order, it's assumed that you notify broker about these 2 or 3 orders at the same time.

            There are number of notifications sent. Some of them such as submitted and accepted goes at the same time. Notifications like completed can't go at the same time by bracket order idea. Your main order can be executed only on the 2nd bar and (logically) you will know this only at the end of the 2nd bar. How do you plan to know at the end of the first bar that it is executed?

            @Anton-Kozin said in Order execution issue:

            It would be great to have something like process_orders_on_close=True, because i have my time for one run increased 2x with this solution.

            Sure, but time machine is not invented yet.

            • If my answer helped, hit reputation up arrow at lower right corner of the post.
            • Python Debugging With Pdb
            • New to python and bt - check this out
            Anton Kozin 1 Reply Last reply Reply Quote 0
            • Anton Kozin
              Anton Kozin @ab_trader last edited by

              @ab_trader said in Order execution issue:

              How do you plan to know at the end of the first bar that it is executed?

              I can know that cause I place an order with exectype=bt.Order.Market, not with Limit one, so I assume that my stop-loss order should be ready to catch the price change from the moment my main order was accepted.

              A Jeffrey C F Wong 2 Replies Last reply Reply Quote 0
              • A
                ab_trader @Anton Kozin last edited by

                @Anton-Kozin said in Order execution issue:

                I can know that cause I place an order with exectype=bt.Order.Market

                market order doesn't have 100% execution guarantee. For example, it will be a gap up next bar, and open price will not allow you to buy the size you wanted cause it will be no funds.

                • If my answer helped, hit reputation up arrow at lower right corner of the post.
                • Python Debugging With Pdb
                • New to python and bt - check this out
                1 Reply Last reply Reply Quote 0
                • Jeffrey C F Wong
                  Jeffrey C F Wong @Anton Kozin last edited by

                  @Anton-Kozin I am trying to do something similar where I failed using cheat-on-open and quicknotify unfortunately. Would it be possible for you to share your solution on how you used next_open?

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