I can't figure out why my algorithm never starts executing any trades. It seems to only calculate the strength close.

 

 

 

class EarningsContinuation(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 9, 14)  # Set Start Date
        self.SetEndDate(2022, 9, 14)
        self.SetCash(100000)  # Set Strategy Cash
        

        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
        self.spy = self.AddEquity('SPY',Resolution.Daily).Symbol

        self.Schedule.On(self.DateRules.EveryDay('SPY'),self.TimeRules.AfterMarketOpen('SPY'), self.Strong)
        
        self.entryTime = datetime.min
        self.openPositions= []
        self.strongclose = 0 


    def CoarseSelectionFunction(self,coarse):
        
        sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
        byprice = [x for x in sortedByDollarVolume if x.DollarVolume > 1000000 and x.Price > 5 and x.HasFundamentalData]
        
        byprice = [x.Symbol for x in byprice][:500]
        
        return byprice

    def FineSelectionFunction(self,fine):
        yesterday = self.Time - timedelta(days=1)
        fineUniverse = [x for x in fine if x.EarningReports.FileDate == yesterday 
                        and x.MarketCap > 5e7]
        tickerSymbolValuesOnly = [c.Symbol for c in fineUniverse]

        return tickerSymbolValuesOnly

    def Strong(self):
        self.strength_dic = {}
        for security in self.ActiveSecurities.Values:
            symbol = security.Symbol

            historyData = self.History(symbol, 2, Resolution.Daily)

            try:
                openDayAfterEarnings = historyData['open'][-1]
                closeDayAfterEarnings = historyData['close'][-1]
                highDayAfterEarnings = historyData['high'][-1]
                closeDayBeforeEarnings = historyData['close'][-2]
                strongclose = (closeDayAfterEarnings - openDayAfterEarnings)/(highDayAfterEarnings-openDayAfterEarnings)
                self.strength_dic[symbol] = strongclose

            except:
                self.Debug(f"History data unavailable for {symbol.Value}")
                continue

            
            
    def OnSecuritiesChanges(self, changes):
        for security in changes.AddedSecurities:
            if self.strength_dic[security.Symbol] > 0.88:
                self.MarketOrder(security,100)
                self.entryTime = Time
                self.openPositions.append(security)
            else:
                continue

    def OnData(self, data: Slice):
        for security in self.openPositions:
            if self.entryTime == (self.entryTime.days + 5) :
                self.MarketOrder(security,-100)
                self.openPositions.remove(security)
            else:
                continue