Overall Statistics
Total Trades
24
Average Win
8.16%
Average Loss
-3.76%
Compounding Annual Return
6.598%
Drawdown
16.200%
Expectancy
0.848
Net Profit
40.035%
Sharpe Ratio
0.669
Probabilistic Sharpe Ratio
21.055%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
2.17
Alpha
0.04
Beta
0.363
Annual Standard Deviation
0.108
Annual Variance
0.012
Information Ratio
-0.114
Tracking Error
0.144
Treynor Ratio
0.199
Total Fees
$607.87
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