Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
entry and exit on time triggers

I really need some help.. I'm trying to write an order command that buys into a security during a set time once daily, say buying only between 9:30 and 9:45, and a sell command to ensure that all my positions are sold prior to the market closing regardless of wether my price triggers were met. Simplicity is my goal and it seems it is above my level of understanding

4 responses

Hello David,

I don't have time right now to cook up an example, but submitting buy orders is straightforward with an if-then statement (e.g. if the time is between 9:30 & 9:45 inclusive, then submit orders). Selling before market close is trickier, since there is no way to know with certainty when the market will close. You could use the same if-then logic, but if the market happens to close early (or trading is suspended for a given security), your sell orders won't get fulfilled within the day.

If you don't get traction on your code within a day or two, just ping me again by posting to this thread.

Grant

https://www.quantopian.com/posts/implementation-of-leveraged-etfs-rebalancing-exploitation-strategy

This one buys at 11am or something, and sells at close, subject to the early closing problem mentioned above.

Thanks Simon. This is the push in the right direction I needed. Thanks Grant i will try to knock it out

Hello David,

If you are really ambitious, you could embed a look-up table in your algorithm that would contain a record of days when the market closed early and the corresponding closing times. Then, you could use the table along with some logic to ensure that you close out your positions every day. Presumably, there would not be a look-ahead bias in this approach, since market participants are informed in advance of early closings. However, before you put too much effort into it, you might check with Quantopian--they may be working on adding other order types that will address these issues.

Grant