To @everyone reading this thread.
The above solution does work, however, there is a better way.
By using the above method by adding two seperate data feeds, resampling them via the timeframe
parameter, and adding them to cerebro.adddata()
(as shown by the code below), create some errors occur with the calculation of technical indicators (like moving average, RSI, stochastic oscillators, etc.) aswell as the line iterator when executing each tick entry in the data source.
The previous used code:
datac = bt.feeds.GenericCSVData(dataname = datapath,
fromdate = datetime.datetime(2021, 1, 4),
todate = datetime.datetime(2021, 4, 1),
dtformat=('%Y-%m-%d'),
tmformat=('%H:%M:%S:%f'),
timeframe=bt.TimeFrame.MicroSecondss,
compression=1,
date=0,
time=1,
open=2, #acts as bid price
high=3,
low=2,
close=3, #acts as ask price
volume=-1,
openinterest=-1
)
datad = bt.feeds.GenericCSVData(dataname = datapath,
fromdate = datetime.datetime(2021, 1, 4),
todate = datetime.datetime(2021, 4, 1),
dtformat=('%Y-%m-%d'),
tmformat=('%H:%M:%S:%f'),
timeframe=bt.TimeFrame.Days,
compression=1,
date=0,
time=1,
open=2,
high=3,
low=-2,
close=3,
volume=-1,
openinterest=-1
)
cerebro.adddata(datac, name='data')
cerebro.adddata(datad, name='data1')
In order to fix this if you want to run your strategy every Tick and compute technical indicators on Bar data (daily bar data, for this instance), this can be rectified by adopting cerebro.replaydata(). See below the alternative method to handeling the Tick data source.
datac = bt.feeds.GenericCSVData(dataname = datapath,
fromdate = datetime.datetime(2021, 1, 4),
todate = datetime.datetime(2021, 2, 8),
dtformat=('%Y%m%d'),
tmformat=('%H:%M:%S:%f'),
timeframe=bt.TimeFrame.MicroSeconds,
compression=1,
date=0,
time=1,
open=2,
high=3,
low=2,
close=3,
volume=4,
openinterest=-1
)
cerebro.replaydata(datac, timeframe=bt.TimeFrame.MicroSeconds, compression=1, name='data')
cerebro.replaydata(datac, timeframe=bt.TimeFrame.Days, compression=1, name='data1')
You can, therefore, still call your Tick data by data.open[0]
and your daily bar data by data1.open[0]