Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Buy/Sell at open price of next period instead of closing price

Hi,

while programming and btesting I have identified another thing that is surprising me.

E.g. when I use this signal here to go short:

if current_price*0.975 >= average_price and cash > current_price:  

    # Need to calculate how many shares we can buy  
    number_of_shares = 100  

    # Place the buy order (positive means buy, negative means sell)  
    order(DJ, -number_of_shares)  
    log.info("Buying %s" % ('DJ'))

It testing the if condition with the close price of the relevant period, which is like expected.

What seems strange is that the order function goes short with the closing price of the following period.

Is there any possibility to change this to the open price of the following period as this is the closest next price after the trigger? Wondering that this is not the default case actually.

Thanks

3 responses

Hi Grant,

is there really no other solution to retrieve the open price of the actual minute bar than use a combination of this model + a hack?

Thanks

You have to use a custom slippage model if you want to modify the execution price, which I gather is what you need to do. Just plug in Anony Mole's code, and you should be all set, no?