Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Order should have filled in backtest but did not

Hi Everyone
Wondered if anyone can help explain why a limit buy order that should have filled because the limit price was between the high and the low for the day, and the order was placed at the open, did not fill.
I have racked my brains but likely missing something obvious.
Attached is the code - the date I was backtesting was 2 Jan 2018, the asset was Toll Brothers.
Much appreciate
Savio

3 responses

The limit order is placed at 9:31 but then immediately canceled in the next line.
At 9:31 on 1-2..
The current open is 48.18
The current price (ie the last close) is 48.31.
The limit price is 47.83.

Therefore the following executes (ie the open price is > limit)

    if ESTdate.hour == 9 and ESTdate.minute == 31 and data.current(stock, 'open') > limit: 

Therefore, the above if statement is true and and and order is created. So far so good. However the following if statement is now executed.

    if data.current(stock, 'price') > 1.01 * limit or data.current(stock, 'price') < 0.95 * limit:

The current price (48.31) is greater than 1.01 x limit (48.308) so the if statement executes and the order is canceled.

Orders aren't filled 'in-line' but rather are simply placed in queue. They are executed at the beginning of the next minute. So, if it's canceled immediately then it will immediately be deleted from the queue and never fill.

Oops I owe you one Dan - missed that completely.
Muchas gracias.

Simulated stop & limit orders. Your post started me rolling just wanting to add some extra help. Then decided to go big. Notice it is using your TOL.