I have been practicing making alpha model with shared project in this community.

I would like to add alpha model but I keep having error message. 

"Runtime Error: TypeError : iteration over non-sequence TypeError : iteration over non-sequence"

 

This is "main.py" file.

import pandas as pd
from SpyTrendAlphaModel import SpyTrendAlphaModel
class MultidimensionalTransdimensionalPrism(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 2, 1)               # Earliest start date for all ETFs in universe 2/1/10
        self.SetEndDate(2020, 5, 6)
        self.SetCash(10000) 
        symbols = [ Symbol.Create("UST", SecurityType.Equity, Market.USA), Symbol.Create("TQQQ", SecurityType.Equity, Market.USA), Symbol.Create("UBT", SecurityType.Equity, Market.USA)]
        
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
        self.SetAlpha(SpyTrendAlphaModel())
        self.SetRiskManagement(CompositeRiskManagementModel(
            MaximumUnrealizedProfitPercentPerSecurity(0.2), 
            MaximumDrawdownPercentPerSecurity(0.3)
            ))
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(NullExecutionModel())

 

 

and this is "SpyTrendAlphaModel.py" file.

class SpyTrendAlphaModel(AlphaModel):
    def __init__(self):
        pass
        
    
    def OnSecuritiesChanged(self, algorithm, changes):
        
        self.symbols = [x.Symbol for x in changes.AddedSecurities]

       
    def Update(self, algorithm, data):
         for x in self.symbols:
            history = algorithm.History(x, 7, Resolution.Daily)
            price = history["close"]
            TF_3 = price.pct_change(3)[-1]
            
            if TF_3 > 0:
                return Insight.Price(price.index[0][0], timedelta(1), InsightDirection.Up)
            else :
                return Insight.Price(price.index[0][0], timedelta(1), InsightDirection.Down)

 

because of the error I could not attach my backtest. 

I would appreciate somebody help me to figure out why I keep getting error msg.

 

Thanks!