Small problem when trading with a lot of different length datas



  • I came into a problem while trading a lot of different length data. I am using MomentumOscilator, with a period as a parameter. I am trading big number of different datas, which have different lengths, so sometimes it happens that len(datas[i]) < period for some datas. Currently, I am just filtering the data in the init method, because MomentumOscilator code is throwing an exception while it is instantiating the data. When I checked the code, it actually seems like really simple change to fix this, in backtrader.linebuffer._once method:

            self.preonce(0, self._minperiod - 1)
            self.oncestart(self._minperiod - 1, self._minperiod)
            self.once(self._minperiod, self.buflen())
    

    could be changed to:

            self.preonce(0, self._minperiod - 1)
            self.oncestart(self._minperiod - 1, min(self.buflen(), self._minperiod))
            self.once(self._minperiod, self.buflen())
    


  • @mpskowron May be that this helps: https://www.backtrader.com/docu/mixing-timeframes/indicators-mixing-timeframes.html

    I'm not sure if it is applicable also to length datas, but it is designed for timeframes of different length


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.