When I use a single time frame I have no trouble resampling my data and implementing it into init exactly the way its shown in the BT documantation:
def __init__(self):
self.atr = bt.indicators.ATR(self.data, period=self.params.atr_per)
self.stoch = bt.indicators.Stochastic(self.data, period=self.params.stoch_per,
period_dslow=self.params.dslow_per)
self.daily_atr = bt.indicators.ATR(self.data1, period=self.params.datr_per)
When I work with multiple data feed I use following code to add it to cerebro:
for i in range(len(symbols)):
dataframe = pandas.read_csv(symbols[i][0], index_col=0,
parse_dates=True,
dayfirst=True
)
data = PandasData(dataname=dataframe, timeframe=bt.TimeFrame.Minutes, compression=5)
cerebro.adddata(data, name=symbols[i][1])
and then following code to implement it into init:
def __init__(self):
self.inds = dict()
for i, d in enumerate(self.datas):
self.inds[d] = dict()
self.inds[d]['atr'] = bt.indicators.ATR(d, period=self.params.atr_per)
self.inds[d]['stoch'] = bt.indicators.Stochastic(d, period=self.params.stoch_per,
period_dslow=self.params.dslow_per)
The code above works perfectly witha single timeframe.
For a single datafeed and multiple timeframe, I have self.data for my intraday data and self.data1 for my daily data which I can pass to the indicators I want and from there on my strategy works as expected.
For multiple datafeeds however, looks like backtrader includes both the 5 min and daily timeframes in same set of feeds (self.datas) and from here on I cannot pass the data I want to the relevant indicators. Not only this but the daily data also messes around with my intraday indicators.
I tried to replicate the above code during init:
self.daily_inds = dict()
for i, d1 in enumerate(self.data1):
self.daily_inds[d1] = dict()
self.daily_inds[d1]['d_atr'] = bt.indicators.ATR(d1, period=5)
but it simply wouldnt work.
Is there a way to prevent daily data messing around with my intraday indicators and use it only for the calculation of the daily indicators?
Daily ATR is important to me as it presents the average daily range for the past few days.
thanks,
Rum