I am receiving the following error upon running my algo (below). The algo is a modified RSI crossover with a trailing stop. Any ideas why this error is coming up? The error refers to the first instance of             self.stopMarketTicket.Update(updateFields). Thanks.
 

Runtime Error: InvalidOperationException : Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.Last[TSource](IEnumerable`1 source)
at QuantConnect.Orders.OrderTicket.Update(UpdateOrderFields fields) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Orders/OrderTicket.cs:line 279 
at OnData
self.stopMarketTicket.Update(updateFields)
===
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 64 (Open Stacktrace)

import numpy as np

class BasicTemplateAlgorithm(QCAlgorithm):
    
    def __init__(self):
        self.stopMarketTicket = None
        self.stopMarketOrderFillTime = datetime.min
        self.stopPrice = 0
        self.risk = 0.95

    def Initialize(self):
        self.cash = 100000
        self.stock = "TQQQ"
        self.SetStartDate(2021,1, 1)  
        self.SetEndDate(2021,11, 12)    
        self.SetCash(self.cash)
        self.AddEquity(self.stock, Resolution.Hour)
        
        #We add our RSI 14 period indicator
        self.rsi = self.RSI(self.stock, 14)
        self.lastrsi = None
        self.SetWarmUp(14)
        
    def OnData(self, data):

        if not self.rsi.IsReady: 
            return
        
        if self.lastrsi is None:
            self.lastrsi = self.rsi.Current.Value
            return 
        
        #If we cross oversold threshold from below
        if self.lastrsi < 30 and self.rsi.Current.Value > 30:
            
            #if we are not currently in a trade
            if not self.Portfolio[self.stock].Invested:
                #we place a long market order
                self.SetHoldings(self.stock, 1.0)
                self.stopMarketTicket = self.StopMarketOrder(self.stock, -self.Portfolio[self.stock].Quantity, self.risk * self.Securities[self.stock].Close)

        #If RSI is oversold while we are short        
        elif self.rsi.Current.Value < 30 and self.Portfolio[self.stock].IsShort:
            # if we are already in a short trade we liquidate
            self.Liquidate()
                     
        #if RSI signals overbought
        if self.lastrsi > 70 and self.rsi.Current.Value < 70:
            
            if not self.Portfolio[self.stock].Invested:
                 #enter short position
                self.SetHoldings(self.stock, -1)
                self.stopMarketTicket = self.StopMarketOrder(self.stock, self.Portfolio[self.stock].Quantity, self.risk * self.Securities[self.stock].Close)
        
        #if RSI is overbought while we are long       
        elif self.rsi.Current.Value > 70 and self.Portfolio[self.stock].IsLong:
            #if we already in a long trade we liquidate 
            self.Liquidate()
        
        if self.Portfolio[self.stock].IsLong and self.Securities[self.stock].Close > self.stopPrice:
            self.stopPrice = self.Securities[self.stock].Close
            updateFields = UpdateOrderFields()
            updateFields.StopPrice = self.stopPrice * self.risk
            self.stopMarketTicket.Update(updateFields)

        elif self.Portfolio[self.stock].IsShort and self.Securities[self.stock].Close < self.stopPrice:
            self.stopPrice = self.Securities[self.stock].Close
            updateFields = UpdateOrderFields()
            updateFields.StopPrice = self.stopPrice * self.risk
            self.stopMarketTicket.Update(updateFields)
        
        #store current RSI value to use later
        self.lastrsi = self.rsi.Current.Value
        
    def OnOrderEvent(self, orderEvent):

        if orderEvent.Status != OrderStatus.Filled: return

        if self.stopMarketTicket is not None and self.stopMarketTicket.OrderId == orderEvent.OrderId:
            self.stopMarketOrderFillTime = self.Time