Indicator as a param for another indicator is NaN
class UpperLines(bt.Indicator): lines = ('upperlines',) params = dict(atr_factor=1.5) res_smooth = 14 res_period = 10 def __init__(self): hsma = bt.talib.SMA(self.data.high, timeperiod=self.res_smooth) res = bt.talib.MAX(hsma, timeperiod=self.res_period) atr = bt.talib.ATR(self.data.high, self.data.low, self.data.close) * self.params.atr_factor self.lines.upperlines = res # TODO: figure out why this line doesn't like 'res' # self.lines.upperlines = res + self.atr
With my current understanding, an indicator is a "line" which then can be played with. So I then would pass
MAXfunction. So my question is: how can I get the values from
bt.talib.SMAto pass into the
MAXfunction, which I believe is responsible for the NaN result of
@run-out That is very odd. Talib works since
bt.talib.SMAis able to return values that isn't NaN and is set and plotted correctly if I just do `self.lines.upperlines = hsma. Perhaps calling the indicator class is wrong?
class BaseStrategy(bt.Strategy): def __init__(self): super().__init__() self.ures = UpperLines() class LinesStrategy(BaseStrategy): params = ( ('maperiod', 15), ) def log(self, txt, dt=None): ''' Logging function for this strategy''' dt = dt or self.datas.datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def __init__(self): # Keep a reference to the "close" line in the data dataseries super().__init__() self.dataclose = self.datas.close def next(self): super().next() # Simply log the closing price of the series from the reference self.log('Close, %.2f' % self.dataclose) print(self.ures)
@run-out Still having a bit of trouble figuring this out. Still
res. Maybe the Strategy implementation/inheritance is wrong as seen above?
run-out last edited by
If your code was running fine on my machine, then the code is good. You have a data or setup with talib problem. Try running the same code I did on a different dataset, something quit different.
@run-out Ah, yup. It's a data-feed problem. Using a different data-feed, everything works as expected. Will look into as to why the data-feed isn't working as expected. Thank you!