Hi,

I used the method mentioned in Algorithmic Trading Lesson to warm up indicators with historical data. However, it does not work. Can anyone help me to fix it. Many thanks.

class HmaIchimokuAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2010, 1, 1)
        self.SetCash(25000)
        self.qqq = self.AddEquity("QQQ", Resolution.Hour).Symbol
        self.hma = self.HMA(self.qqq, 12, Resolution.Hour)
        self.delayed_hma = IndicatorExtensions.Of(Delay(2), self.hma)
        
        # ==== System Inputs ====
        TenkanPeriod = 9
        KijunPeriod = 26
        SenkouAPeriod = 26
        SenkouBPeriod = 52
        SenkouADelay = 26
        SenkouBDelay = 26
        
        self.ichimoku = self.ICHIMOKU(self.qqq, TenkanPeriod, KijunPeriod, SenkouAPeriod, SenkouBPeriod, SenkouADelay, SenkouBDelay, Resolution.Hour)
        
        closing_prices = self.History(self.qqq, 52, Resolution.Hour)["close"]
        for time, price in closing_prices.loc[self.qqq].items():
            self.hma.Update(time, price)
            self.delayed_hma.Update(time, price)
            self.ichimoku.Update(time, price)
        
        
    def OnData(self, data):
        if not (self.qqq in data.Bars and self.hma.IsReady and self.delayed_hma.IsReady and self.ichimoku.IsReady): 
            return
        
        history = self.History(self.qqq, 52, Resolution.Hour)
        self.hma = SelectionData(self.qqq, history)
        self.delayed_hma = SelectionData(self.qqq, history)
        self.ichimoku = SelectionData(self.qqq, history)
        
        price = self.Securities["QQQ"].Price
    
        currentHma = self.hma.Current.Value
        previousHma = self.delayed_hma.Current.Value
        
        tenkan = self.ichimoku.Tenkan.Current.Value
        kijun = self.ichimoku.Kijun.Current.Value
        chikou = self.ichimoku.Chikou.Current.Value
    
        senkou_span_a = self.ichimoku.SenkouA.Current.Value
        senkou_span_b = self.ichimoku.SenkouB.Current.Value
        cloud_top = max(senkou_span_a, senkou_span_b)
        cloud_bottom = min(senkou_span_a, senkou_span_b)
        
        
        if not self.Portfolio.Invested and currentHma > previousHma and price > previousHma and price > chikou and price > cloud_top and (tenkan >= kijun or price > kijun):
            self.SetHoldings("QQQ",1)
            
        elif not self.Portfolio.Invested and currentHma < previousHma and price < previousHma and price < chikou and price < cloud_bottom and (tenkan <= kijun or price < kijun):
            self.SetHoldings("QQQ",-1)    
            
        # Liquidate         
        if self.Portfolio["QQQ"].IsLong and currentHma < previousHma and (price < previousHma or tenkan < kijun or price < tenkan or price < kijun or price < cloud_top or price < chikou):
            self.Liquidate()
                
        elif self.Portfolio["QQQ"].IsShort and currentHma > previousHma and (price > previousHma or tenkan > kijun or price > tenkan or price > kijun or price > cloud_bottom or price > chikou):
            self.Liquidate()

           

 

Author