Hi there, 

I am getting an error:

def OnData(self, data):

if self.sma20.Current.Value >= self.sma150.Current.Value:
if self.flag3 > 0:
if self.flag2 == 1:
self.flag2 = 0

if self._changes == None: return

for security in self._changes.RemovedSecurities:
if security.Invested:
self.Liquidate(security.Symbol)

for security in self._changes.AddedSecurities:
self.SetHoldings(security.Symbol, 0.8/float(len(self._changes.AddedSecurities)))

self._changes = None


if self.sma20.Current.Value < self.sma150.Current.Value:
if security.Invested:
self.Liquidate(security.Symbol)

Runtime Error: UnboundLocalError : local variable 'security' referenced before assignment
at OnData in main.py:line 119
UnboundLocalError : local variable 'security' referenced before assignment (Open Stacktrace)

**Line 119 corresponds to "if security.Invested:"

I was wondering if someone would be able to help me out, thanks.