class BasicTemplateAlgorithm(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2017,01,01) #Set Start Date

self.SetEndDate(2017,12,31) #Set End Date

self.SetCash(100000) #Set Strategy Cash

self.AddEquity("SPY")

# below creates a 200 day exponential moving average

self.slow = self.EMA("SPY", 200, Resolution.Daily);

self.previous = None

def OnData(self, data):

if not self.slow.IsReady:

return

if self.previous is not None and self.previous.date() == self.Time.date():

return

holdings = self.Portfolio["SPY"].Quantity

if holdings <= 0:

if self.slow.Current.Value < self.Securities["SPY"].Price

self.Log("BUY >> {0}".format(self.Securities["SPY"].Price))

self.SetHoldings("SPY", 1.0)

if holdings > 0 and self.slow > self.Securities["SPY"].Price

self.Log("SELL >> {0}".format(self.Securities["SPY"].Price))

self.Liquidate("SPY")

self.previous = self.Time