Hello Everyone,

I am trying to create a momentum strategy comparing equal eighted momentum indicators between SPY,EEM and TLT. The plan is to modify the weights based on overall market strategy and create a momentum strategy that becomes aggressive/neutral/defensive based on rate of change of vix. 

I do not have any technical background and whatever I have coded is by learning through Udemy/Youtube tutorials. I will deeply appreciate if someone can point out what I am doing wrong in the attached code.

ass MomentumBasedTacticalAllocation(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2007, 1,1)
self.SetEndDate(2020,12,1)
self.SetCash(3000)

self.spy = self.AddEquity("SPY", Resolution.Daily)
self.bnd = self.AddEquity("TLT", Resolution.Daily)
self.eem = self.AddEquity("EEM",Resolution.Daily)

self.spyMomentum30 = self.MOMP("SPY", 30, Resolution.Daily)
self.spyMomentum60 = self.MOMP("SPY", 60, Resolution.Daily)
self.spyMomentum90 = self.MOMP("SPY", 90, Resolution.Daily)
self.spyaverage = (self.spyMomentum30()+self.spyMomentum60()+self.spyMomentum90())/3


self.bondMomentum30 = self.MOMP("BND", 30, Resolution.Daily)
self.bondMomentum60 = self.MOMP("BND", 60, Resolution.Daily)
self.bondMomentum90 = self.MOMP("BND", 90, Resolution.Daily)
self.bondavg = (self.bondMomentum30()+self.bondMomentum60()+self.bondMomentum90())/3

self.eemMomentum30 = self.MOMP("EEM", 30, Resolution.Daily)
self.eemMomentum60 = self.MOMP("EEM", 60, Resolution.Daily)
self.eemMomentum90 = self.MOMP("EEM", 90, Resolution.Daily)
self.eemavg = (self.eemMomentum30()+self.eemMomentum60()+self.eemMomentum90())/3

self.SetBenchmark(self.spy.Symbol)
self.SetWarmUp(90)

def OnData(self, data):

if self.IsWarmingUp:
return

#1. Limit trading to happen once per month
if not self.Time.month() == 1:
return

if self.spyavg.Current.Value > self.eemavg.Current.Value > self.bndavg.Current.Value:
self.Liquidate("TLT")
self.Liquidate("EEM")
self.SetHoldings("SPY", 1)

else:
if self.eemavg.Current.Value > self.spyavg.Current.Value > self.bndavg.Current.Value:
self.Liquidate("TLT")
self.Liquidate("EEM")
self.SetHoldings("SPY", 1)

else:
self.Liquidate("SPY")
self.Liquidate("EEM")
self.SetHoldings("TLT", 1)