For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Indicators & Machine Learning

  • 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(
        current_date = self.datas[0].datetime
        prices = [[[-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[0] = pred_prices[0]          # <---- this is okay, but it's not my objective.

    Could u plz tell me how to do it? I appreciate your help.

  • administrators

    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 collections.deque with a maxlen during creation), push the last predicted value and pop the value from the left which is the current value.