Cannot access the resampled data in self defined indicators
I had a data source in Minutes time frame, and I resampled it into 15 minutes data. However, I cannot get the resample data value in my custom Indicators' __init__ function (it calls some talib functions). It says "Exception: inputs are all NaN". Is there anything wrong?
Is there anything wrong?
Knowledge osmosis is not yet possible. No data, no code, no nothing ... no answer
The data look like this, being 1MIN kline and have been added.
Then, I resample it with cerebro.resample(data, timeframe=bt.TimeFrame.Minutes, compression=15), hoping to get klines of 15MIN.
It can be accessed in bt.indicators.SimpleMovingAverage(self.datas.close, period=30) and it works fine.
However, when the indicator is defined by myself, for example,
class SMACustIndicator(Indicator): lines = ('sma_cust',) params = ( ('period', 30), ) plotinfo = dict(subplot=False) def __init__(self): self.sma_cust = talib.SMA( pd.Series(self.data.close.array), timeperiod=self.params.period ) def next(self): cur = len(self) self.lines.sma_cust = self.sma_cust.iloc[cur-1, ]
It raises "Exception: inputs are all NaN".
def __init__(self): self.sma_cust = talib.SMA( pd.Series(self.data.close.array), timeperiod=self.params.period )
At that stage there is no data available, which means you are creating a
NaN, hence the result.
ta-libis integrated with backtrader, use the integration directly. Doc - Indicators - ta-lib
One more question, do you mean, the data will only be filled at next() calls?
No, I mean that you are initializing a
pd.Serieswith an array which is full of