I'm creating a class-based signal generator that, given a buy threshold, sell threshold and a list of list of indicators, creates a 'buy' of 'sell' signal on a given day if the indicator from that day is greater than the sell threshold.
But the day before it wasn't greater, so basically when the indicator crosses over the buy threshold, it gives a sell signal and a buy signal when the indicator crosses under the buy threshold (it's lower than the threshold on a day, but the day before it wasn't).
I am wondering if this working code could be cleaned up using zip.
class Directionalindicator_signals():
def __init__(self, buy_threshold, sell_threshold, list_of_indicators):
self.buy_threshold = buy_threshold
self.sell_threshold = sell_threshold
self.list_of_indicators = list_of_indicators
def calculate(self):
signals = ['']
for i in range(1, len(self.list_of_indicators)):
if self.list_of_indicators[i] > self.buy_threshold and self.list_of_indicators[i-1] <= self.buy_threshold:
signals.append('Sell')
elif self.list_of_indicators[i] < self.buy_threshold and self.list_of_indicators[i-1] >= self.buy_threshold:
signals.append('Buy')
else:
signals.append('')
return signals