Which line in the data is SimpleMovingAverage based on?



  • In https://www.backtrader.com/docu/concepts.html , a moving average is constructed like this:

    sma = btind.SimpleMovingAverage(self.datas[0], period=self.params.period)

    Wouldn't self.datas[0] contain several lines, i.e. self.datas[0].lines.close, self.datas[0].lines.open, self.datas[0].lines.min, etc. according to whatever columns are in our data table?

    Which of these lines is the SMA based on? Follow up: does it ASSUME that we want compute SMA on "close" and are therefore required to include a "close" line in every data feed that is sent to the SMA function?


  • administrators

    No. If no specific line is passed, the 1st defined line is used. In the case of regular data feeds, close is defined as the 1st line to match the de-facto standard which is to do things directly on the close price.


Log in to reply
 

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