I want to calculate accumulate sum of trading volume at 9:30 AM each day, and do it in next
method of Indicator class, like this:
class MyLine(bt.Indicator):
lines = ('AccVol',)
params = (('bar_count', 30),)
def __init__(self):
self.time=self.data0.datetime.time()
def next(self):
print(self.time)
# calculate accumulate volume at specific time of each day
class MyStrategy(bt.Strategy):
params = dict(
bar_count=30,
)
def __init__(self):
self.MyLine = MyLine(self.data, bar_count=self.p.bar_count)
def next(self):
print(self.data.datetime.time())
cerebro = bt.Cerebro(runonce=False)
all_stock = np.load('stockdata.npy', allow_pickle='TRUE').item()
dataframe = all_stock['1101']
data = bt.feeds.PandasData(dataname=dataframe, fromdate=datetime.datetime(2022, 11, 1), todate=datetime.datetime(2022, 11, 30), timeframe=bt.TimeFrame.Minutes)
cerebro.adddata(data)
cerebro.addstrategy(MyStrategy)
cerebro.run(runonce=False)
However, the print(self.time) in next method of MyLine class always print 13:30:00 (which is market closing time of each day), desipte the print(self.data.datetime.time()) in next method of MyStrategy could correctly print every minute.
What's wrong with my code, or is there better suggestion?
Thank you for any help you can provide.