How to deal with multiple stocks data with multiple timeframes?
Suraj Thorat last edited by
There is an example of using backtrader for multiple stocks and one for using multiple timeframes. Is there an example available to use both together? I want to get a signal on weekly data and buy if another signal on end of day data is satisfied.
Mark Weaver last edited by
@Suraj-Thorat I've had similar challenge.. I've settled on doing something like this in init and next. I check the _compression of the data to determine which datafeeds i want to setup indicators for, run calculations against, etc
def next(self): if data._compression==self.p.largerCompression: # do the larger timeframe stuff here if data._compression==self.p.smallerCompression: # do the smaller timeframe stuff here
I've been able to add pairs of data feeds, one for each timeframe, for a couple dozen stocks and run them against months of data.. (takes a while obviously)
ab_trader last edited by
What is your particular concern? It seems an approach is straight forward - in
forloop add daily data feed, then resample it to weekly data feed. Now all odd data feeds are daily, all even data feeds are weekly. In the
forloop apply signal indicators to even data feeds, apply confirmation indicators to odd data feeds. Check the signals and then issue the orders against odd data feeds.