I started to study "backtesting" and during testing I encountered one incomprehensible situation.
class MyCandlesStrat(Strategy):
def init(self):
super().init()
self.signal1 = self.I(SIGNAL)
def next(self):
super().next()
if self.signal1==1:
self.buy()
elif self.signal1==-1:
self.sell()
above is the strategy test code, but I can't figure out how to indicate that the signal = 0, did it close the order?
UPD : Signal column contains signals. in the code above, only trades are opened and not closed.
0
0
0
1
1
1
1
1
0
-1
-1
-1
-1
-1
-1
0
0
0
1
1
1
1
after a little digging on the net, I added the code class MyCandlesStrat(Strategy): def init(self): super().init() self.signal1 = self.I(SIGNAL)
def next(self):
super().next()
if self.signal1 ==1:
self.position.close()
self.buy()
elif self.signal1 ==-1:
self.position.close()
self.sell()
else:
self.signal1 == 0
self.position.close()
But it's still not what I want. This code closes deals with the same signals and does not
I want to understand how to implement "buy and hold until the signal is the same" or "sell and hold while the signal is the same" ??