Hello, 

I'm doing a little experiment with tick data, I keep getting this error 

Runtime Error: TypeError : 'NoneType' object is not subscriptable
  at OnData
    quantity = 0 if slice[self.ibm][-1].Quantity is None else slice[self.ibm][-1].Quantity
===
   at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 24
	 (Open Stacktrace)

even checking if the current slice contains the key 

if not self.CurrentSlice.ContainsKey(self.ibm):
            return

the code works at first but at some point I get the error, could it be a tick missing? 

Thanks for the help!

here's the code

class RetrospectiveRedSalmon(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 11, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        
        self.ibm = self.AddEquity("IBM", Resolution.Tick).Symbol

        self.sum = 0
        self.td = 10000000
        self.n = 1
        self.count = 0
        
        self.Schedule.On(self.DateRules.On(2021,11, 14), self.TimeRules.At(15,45), self.ExitPositions)
                        
    def OnData(self, slice):
        
        if not self.CurrentSlice.ContainsKey(self.ibm):
            return
        
        #self.Debug(f"Last price: {tick[-1].LastPrice}")
        #self.Debug(f"Last Quantity: {tick[-1].Quantity}")
        
        quantity = 0 if slice[self.ibm][-1].Quantity is None else slice[self.ibm][-1].Quantity 
        
        
        self.sum = quantity + self.sum #slice['AAPL'] instead of ticks
        tl = []
        
        if abs(self.sum)/self.n == self.td:
            tl[(self.n - 1)] = self.sum/self.n
            if tl[-1] > 0 and tl[-2] is not None:
                if tl[-2] > 0:
                    self.count = self.count + 1
        else:
            return
        
        self.n = self.n + 1
        
    def ExitPositions(self):
        self.Liquidate() 
        self.Debug("p estimate: " + str(self.count))