Overall Statistics
import numpy as np
from datetime import timedelta

class BasicTemplateAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2018,7, 10)  #Set Start Date
        self.SetEndDate(2018,7,20)    #Set End Date
        self.SetCash(100000)           #Set Strategy Cash
        self.AddEquity("SPY", Resolution.Minute)
        consolidator = TradeBarConsolidator(15)
        consolidator2 = TradeBarConsolidator(60)
        self._sma = SimpleMovingAverage(60)
        self._ema = ExponentialMovingAverage(15)
        self.RegisterIndicator("SPY", self._sma, consolidator)
        self.RegisterIndicator("SPY", self._ema, consolidator2)
        self.SubscriptionManager.AddConsolidator("SPY", consolidator)
        self.SubscriptionManager.AddConsolidator("SPY", consolidator2)
        self.Schedule.On(self.DateRules.EveryDay(),self.TimeRules.Every(timedelta(minutes=15)), self.Trade)

    def Trade(self):
        if self._ema.IsReady and self._sma.IsReady:
            if self._ema.Current.Value > self._sma.Current.Value:
                self
                if(self.Portfolio["SPY"].IsShort == True):
                    self.Liquidate()
                self.SetHoldings("SPY",1)
            elif self._ema.Current.Value < self._sma.Current.Value:
                self.Log("short")
                if(self.Portfolio["SPY"].IsLong == True):
                    self.Liquidate()
                self.SetHoldings("SPY",-1)

    def OnData(self, data):
        pass