Limit order with a day valid never gets executed? #220
Thanks for the detail explanation, after I set cash value, it works perfectly. Thanks again.
I had a similar problem and resolved by canceling the pending order every and then recreating it. This way there's no "weekend problem" when the order for next day is more than one day ahead.
def next(self): self.cancel(self.order) ... if not self.position: self.order = self.buy(price = buy_price, exectype = bt.Order.Limit) else: self.order = self.close(price = sell_price, exectype = bt.Order.Limit)
I am using the following code to buy at the high of a bar and cancel it if it does not get filled the next day.
eofthisday = dt.datetime.combine(self.data.datetime.date(),dt.time(23, 59,59, 9999)) eofnextday = eofthisday + dt.timedelta(days=1) self.order = self.buy(exectype=bt.Order.Stop, size=100, price=self.data.high, valid=eofnextday)
For some reason, the program is only half working. Below is a buying log of the program
On 2016-04-28 (the first signal), the high of the next day was not higher than that of 2016-04-28, and it should be cancelled. But when the signal came on 2016-04-29, the high of 2016-05-02 (the next day) was higher than that of 2016-04-29, but the program did not buy until 2016-06-06. Could someone please explain what I am doing wrong?
@rishabmah5 I meant 2016-05-05
run-out last edited by
@rishabmah5 It would be significantly more helpful if you supplied OHLC data for each bar, if we are going to analyze OHLC to answer the question.