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



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



  • 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).



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



  • @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.



  • @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.



  • @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.


Log in to reply
 

});