Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Small problem when trading with a lot of different length datas

    General Discussion
    2
    2
    910
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mpskowron last edited by

      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())
      
      C 1 Reply Last reply Reply Quote 0
      • C
        Chapachan @mpskowron last edited by Chapachan

        @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

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors