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/

    Question about the implement of SimpleMovingAverage

    General Discussion
    2
    3
    1014
    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.
    • Johnny Cui
      Johnny Cui last edited by

      here is the code

      sma1 = btind.SimpleMovingAverage(self.datas[0], period=self.p.period1)
      sma2 = btind.SimpleMovingAverage(sma1, period=self.p.period2)
      

      I understand how it get the value sma1 .There exists a buffer, while the program feed the data from first to end ,it store the history data in the buffer, so it is easy to get the sma1.
      But how the function get the value sma2? Except the sma1 , it know nothing else, is there anther buffer to sotre the history data of the sma1?

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        Backtrader will create a startup buffer for sma1, and then will start a buffer for sma2 once the first sma1 is complete.

        So if self.p.period is 20 days, The first buffer will be at 20 days, and then the sma1 will need 20 more days to get an 20 period average of sma1.

        RunBacktest.com

        1 Reply Last reply Reply Quote 0
        • Johnny Cui
          Johnny Cui last edited by

          thank you so much! got it~

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