For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

How to deal with multiple stocks data with multiple timeframes?

  • 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.

  • @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)

  • What is your particular concern? It seems an approach is straight forward - in for loop 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 for loop 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.

Log in to reply