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
hsma
into aMAX
function. So my question is: how can I get the values frombt.talib.SMA
to pass into theMAX
function, which I believe is responsible for the NaN result ofres
? -
@run-out That is very odd. Talib works since
bt.talib.SMA
is 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[0].datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries super().__init__() self.dataclose = self.datas[0].close def next(self): super().next() # Simply log the closing price of the series from the reference self.log('Close, %.2f' % self.dataclose[0]) print(self.ures[0])
-
@run-out Still having a bit of trouble figuring this out. Still
NaN
forres
. Maybe the Strategy implementation/inheritance is wrong as seen above? -
@leggomaeggo
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!