Force bracket to close at the end of the day
I have read the docs, searched and forums and google searched quite a lot. I would like to set up my strategy to be forced to sell at the end of each day.
My data is hourly. I have tried to count bars but this is a little limiting. I have read about different order execution types (MOC), but I'm not sure how to implement that in a bracket order or how to break it apart and do it manually.
I have read about the idea of pre-loading data, but I very much would like to be able to convert this to live data if I needed to quite easily, so ideally I would be able setup some way. Ideas?
but I'm not sure how to implement that in a bracket order
I don't think that's a realistic scenario with a broker, because a
Market-On-Closeorder is a
Marketoder per se and has no price tag associated. And a bracket by definition has price tags for the orders around the main order, hence the name bracket.
Your best bet:
- Issue an order and await execution
- With the execution in the hand create 3 orders: upper side, lower side, MoC as OCO orders - See Docs - OCO Orders
- If any of them execute the others will be cancelled.
In any case, it may still not be supported by your broker.
Furthering on this idea of buying/selling at the close of a day; I can't think about how to do it.
One idea is to set a marketorder for daily bars, but that won't really hold up during live trading.
Another idea would be to buy a small stake at open, count the bars and then buy more when you know it is at the end of the day with Market Order.
I'm not sure how to implement a Market-On-Close or a Market Order for the last bar of the day. Any thoughts?
Just an idea - looks like you are trading intraday, check the timestamp of the each bar, then at 1 bar before the end of a session cancel all active limit and stop orders and issue the market order to close the position - just
self.close()It should be executed at the
openof last bar.
That's a fantastic idea, I can't believe I didn't think about that. Thank you