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/88I 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) orcheat-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
andaccepted
goes at the same time. Notifications likecompleted
can't go at the same time bybracket
order idea. Yourmain
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 withLimit
one, so I assume that my stop-loss order should be ready to catch the price change from the moment mymain
order wasaccepted
. -
@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, andopen
price will not allow you to buy the size you wanted cause it will be no funds. -
@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?