Back

How to access previous SMA data in the MultipleSymbolConsolidationAlgorithm.py algorithm.

I am trying to access the previous period SMA indicator values. As an example, I want to get the value of the SMA(10 period) 5 bars in the past. What is the correct syntax for accessing the previous SMA indicator values?

I can access the bar data with 'self.Data[symbol].Bars[0].Low', where the '0' of 'Bars[0]' is the most recent and '1' is the previous bar data etc.
Low is the low of the bar.  I can also access the Time, High, Open and Close for each bar.
    
I have not been able to determine how to access the previous data for the SMA indicator. I can access the current value with 'self.Data[symbol].SMA.Current.Value' but I am not sure of how to access the previous data.  I have tried 'self.Data[symbol].SMA[1]' and I get 'unindexable object' error.
    
My question is what do I need to do to access the previous value of the SMA indicator?

I have attached the backtest of the algorithm.
You can see the self.Debug() statement at the end of the OnData(self,data) section.

I appreciate the help.

Update Backtest








Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed