@run-out said in it seems dead loop if just simple cross strategy:
@goldcar said in it seems dead loop if just simple cross strategy:
if self.position.size == 0: if self.k[0] > self.d[0] : self.order = self.buy() else: self.order = self.sell() elif self.position.size < 0: if self.k[0] > self.d[0] : self.order = self.close() elif self.position.size > 0: if self.k[0] < self.d[0] : self.order = self.close()You will only execute one of these conditionals per loop. This means that you cannot close and go short for example, in the same loop, using this code. You should also note that the buys and sells will not happen instantly. So to correct you may wish to try the following:
if self.k[0] > self.d[0]: if self.position: self.close() self.order = self.buy() elif self.k[0] < self.d[0]: if self.position: self.close() self.order = self.sell()
oh...I see. thanks a lot