Overall Statistics
import datetime as datetime

class Algorithm (QCAlgorithm):
    def Initialize(self):
        self.SetCash(1000000)
        self.SetStartDate(2015, 1, 1)
        self.SetBrokerageModel(BrokerageName.AlphaStreams)
        self.AddEquity("SPY", Resolution.Hour)
        self.liquidated = self.Time + datetime.timedelta(weeks=-8)
        self.high = 0
    
    def OnData(self, data):
        
        if not self.Portfolio.Invested and self.Time > self.liquidated:
            self.SetHoldings("SPY", 1)
        
        if self.Portfolio.Invested and data["SPY"] is not None:
            
            if data["SPY"].High > self.high:
                self.high = data["SPY"].High
        
            close = data["SPY"].Close
            dd = (close - self.high) / close
        
            if dd < -0.06:
                self.Liquidate()
                self.liquidated = self.Time + datetime.timedelta(weeks=+4)
                self.high = 0