Put stop order that valid at each TimeFrame
I need to put a limit order in each TimeFrame and it has to be valid just for that TimeFrame. I used the following code, but it did not cancel the orders at the end of each TimeFrame:
self.buy(exectype = bt.Order.Stop, price = price, valid = datetime.datetime.now() + datetime.timedelta(minutes=1))
Is this right?
Since it does not work, first I cancel all previous orders at the beginning of the next(self), by this code:
[self.cancel(o) for o in self.broker.orders if o.status < 4]
and then I put the stop order. This action works, but makes the calculation process really slow. Is there any way to optimize this action?