For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Indicator NaN in Strategy class but not in Indicator class
-
I am missing something such that the indicator line isn't being read properly in the strategy, but is read properly in the indicator itself?
class SlopeCalc(bt.Indicator): lines = ('slopescalcs',) params = dict(typeToCalc='volatility', period=5) def __init__(self): if self.params.typeToCalc == 'volatility': self.lines.slopecalc = bt.talib.VAR(self.data.close, timeperiod=self.params.period, nbdev=1.0) def next(self): print("in ind", self.lines.slopecalc[0])
class LaneStrategy(bt.Strategy): 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 self.dataclose = self.datas[0].close self.slopevolat = SlopeCalc() def next(self): print("in strat",self.slopevolat[0])
Printing yields:
in ind 6.162160000044992e-07 in strat nan in ind 5.590959997192613e-07 in strat nan in ind 3.006904000013577e-06 in strat nan in ind 8.901303999886423e-06 in strat nan in ind 1.0513023999569882e-05 in strat nan in ind 6.540775999708259e-06 in strat nan in ind 4.6533039999019365e-06 in strat nan in ind 1.3609624000210374e-05 in strat nan in ind 2.923282400013605e-05 in strat nan in ind 2.4948944000069417e-05 in strat nan in ind 1.0268935999757645e-05 .....
-
@leggomaeggo said in Indicator NaN in Strategy class but not in Indicator class:
lines = ('slopescalcs',)
Missing an
s
if self.params.typeToCalc == 'volatility': self.lines.slopecalc = bt.talib.VAR(self.data.close, timeperiod=self.params.period, nbdev=1.0)