Problem with too many closing trades.
Jeffrey C F Wong last edited by
Hi everyone, I have the following codes where
crossover_exitshould only close when there is an existing long order and
crossunder_exitshould close when there is a ongoing short order. But my results shows that it is closes a trade whenever there is a
crossunder_exitcondition, resulting in too many closes. It'd be great if someone can shine some light on this. Thank you in advance.
if not self.position: if self.crossover: self.buy() if self.crossunder: self.sell() if self.position.size!=0: if self.position is self.buy and self.crossover_exit: self.close() if self.position is self.sell and self.crossunder_exit: self.close()