Indicators & Machine Learning
Sahli Simo last edited by Sahli Simo
Lets say that I developed an indicator to predict stock prices for the following 5 days.
I followed your tutorial and I could write a custom indicator class. But I couldnt assign the values for the coming 4 days for example. Maybe the following code will show the problem
class AlphayaPredictor(bt.Indicator): lines = ('lstm',) params = (('period', 5),) plotinfo = dict(subplot=False) # def __init__(self): # self.addminperiod(self.params.period) def next(self): # datasum = math.fsum(self.data.get(size=self.params.period)) current_date = self.datas.datetime prices = [[self.data.open[-i], self.data.high[-i], self.data.low[-i], self.data.close[-i], self.data.volume[-i] ] for i in range(self.params.period-1,-1,-1)] pred_prices = predict_future_prices(prices) # it returns a list of future prices for i in range(self.params.period): self.lines.lstm[i] = pred_prices[i] # <---- here is the problem # self.lines.lstm = pred_prices # <---- this is okay, but it's not my objective.
Could u plz tell me how to do it? I appreciate your help.
You cannot put values into the future, which is what you are trying to do.
Keep the values in a ring buffer (use for example
maxlenduring creation), push the last predicted value and pop the value from the left which is the current value.