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



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



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



  • thank you so much! got it~


Log in to reply
 

});