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?
-
@yoghurtshawn said in Cannot access the resampled data in self defined indicators:
Is there anything wrong?
Knowledge osmosis is not yet possible. No data, no code, no nothing ... no answer
-
Sorry.
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[1].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[0] = self.sma_cust.iloc[cur-1, ]
It raises "Exception: inputs are all NaN".
-
@yoghurtshawn said in Cannot access the resampled data in self defined indicators:
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
pd.Series
full ofNaN
, hence the result.ta-lib
is integrated with backtrader, use the integration directly. Doc - Indicators - ta-lib -
Thanks! @backtrader
One more question, do you mean, the data will only be filled at next() calls?
-
No, I mean that you are initializing a
pd.Series
with an array which is full ofNaN
values.