Overall Statistics
Total Trades
36
Average Win
0.14%
Average Loss
-0.17%
Compounding Annual Return
-6.127%
Drawdown
2.000%
Expectancy
-0.391
Net Profit
-1.205%
Sharpe Ratio
-2.256
Loss Rate
67%
Win Rate
33%
Profit-Loss Ratio
0.83
Alpha
-0.083
Beta
0.022
Annual Standard Deviation
0.029
Annual Variance
0.001
Information Ratio
-4.598
Tracking Error
0.197
Treynor Ratio
-2.99
Total Fees
$36.00
class CommunityTemplate(QCAlgorithm):

    def Initialize(self):
        self.ticker = 'SPY'
        self.AddEquity(self.ticker, Resolution.Daily)
        self.SetBenchmark(self.ticker)
        self.symbol_ = self.Symbol(self.ticker)
        self.cash = 100000
        self.SetCash(self.cash)
        self.SetStartDate(2018, 12, 22) 
        self.SetEndDate(2019, 3, 1)

        #already_traded = False
        #usa_after_hours = True
        
        #opentime = self.TimeRules.At(9, 30)
        #closetime = self.TimeRules.At(15, 59, 45)
        #if int(self.time) >= int(opentime) and <= int(closetime):
        
        '''
        if self.IsMarketOpen:
            usa_after_hours = False
        elif not self.IsMarketOpen:
            usa_after_hours = True
        '''
        
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Friday), self.TimeRules.At(15, 0), self.endOfWeek)
        self.Consolidate(self.ticker, CalendarType.Weekly, self.CalendarTradeBarHandler)
        self.window = RollingWindow[TradeBar](2)
    def CalendarTradeBarHandler(self, tradeBar):
        self.window.Add(tradeBar)
        self.Log(f'{tradeBar.Time}: {tradeBar.Open} - {tradeBar.EndTime}: {tradeBar.Close}')
    
    def endOfWeek(self):
        self.Liquidate(self.symbol_)
   
    def OnData(self, data):
        if not (self.window.IsReady): return
    
        currBar = self.window[0] # Current bar had index zero.
        pastBar = self.window[1]
        currP = self.Securities[self.ticker].Price
        prehigh = pastBar.High
        
        if not self.Portfolio.Invested: #and already_traded and not usa_after_hours:
            if currP > prehigh: #'''basic conditional statement'''
                self.SetHoldings(self.ticker, .01)
                self.MarketOrder(self.ticker, 200)
                self.LimitOrder(self.ticker, -200 , prehigh * 1.001)
                #already_traded = True