Back

BollingerBands as IndicatorDataPoint using consolidated data

Hi all,

I'm attempting to obtain BollingerBand's UpperBand and LowerBand properties from an IndicatorDataPoint  object provided by the update method of my consolidator.  I've tried a number of approaches, and perhaps this is due to my shortcomings with Python, but haven't had any luck obtaining these properties from BollingerBands.

The error I get is:

AttributeError : 'IndicatorDataPoint' object has no attribute 'UpperBand'

I would greatly appreciate guidance, or if this is possible.  Thanks in advance.

 

class BBConsolidatorTest(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 5, 1) 
        self.SetEndDate(datetime.now()) 
        self.SetCash(1000000) 

        future = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Tick)
        future.SetFilter(lambda x: x.FrontMonth().OnlyApplyFilterAtMarketOpen())

        self.symbol = None
        self.consolidators = dict()
        self.quoteBarWindow = RollingWindow[QuoteBar](100)

        self.BBIndicator = BollingerBands(12, 2, MovingAverageType.Simple)
        self.BBIndicator.Updated += self.BBUpdated
        self.BBWindow = RollingWindow[IndicatorDataPoint](4)

    def OnDataConsolidated(self, sender, quoteBar):
        self.Debug(str(self.BBWindow[0].UpperBand.Value))
        self.Debug(str(self.BBWindow[0].LowerBand.Value))

    def OnData(self, slice):
        return

    def BBUpdated(self, sender, updated):
        self.BBWindow.Add(updated)

    def OnSecuritiesChanged(self, changes):
        if len(changes.RemovedSecurities) > 0:
            if self.symbol is not None and self.consolidator is not None:
                self.SubscriptionManager.RemoveConsolidator(self.symbol, self.consolidator)
                self.BBIndicator.Reset()

        self.symbol = changes.AddedSecurities[0].Symbol

        # Create a new consolidator and register the indicators to it
        consolidator = TickQuoteBarConsolidator(900)
        consolidator.DataConsolidated += self.OnDataConsolidated
        self.SubscriptionManager.AddConsolidator(self.symbol, consolidator)
        self.consolidators[self.symbol] = consolidator
        self.RegisterIndicator(self.symbol, self.BBIndicator, consolidator)

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.


Hi Earthman,

The objects stored in BBWindow are of type IndicatorDataPoint. This class does not have an UpperBand property. We need to create two RollingWindows if we want to access the historical upper and lower band values for this indicator. View the attached backtest for an example.

Best,
Derek Melchin

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.


Ah yes, wondered if this was the best practice.  This does nicely.  Thanks for the help.

0

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