Overall Statistics
Total Trades
332
Average Win
0.14%
Average Loss
-0.17%
Compounding Annual Return
-1.524%
Drawdown
5.100%
Expectancy
-0.070
Net Profit
-2.098%
Sharpe Ratio
-0.279
Probabilistic Sharpe Ratio
5.161%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
0.84
Alpha
-0.026
Beta
0.019
Annual Standard Deviation
0.05
Annual Variance
0.003
Information Ratio
-1.506
Tracking Error
0.423
Treynor Ratio
-0.737
Total Fees
$0.00
Estimated Strategy Capacity
$9000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
class UglyMagentaRhinoceros(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)  # Set Start Date
        #self.SetEndDate(2020,11,19)
        self.SetCash(10000)  # Set Strategy Cash
        #self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        
        aapl = self.AddEquity("AAPL", Resolution.Minute)
        
        self.symbol = aapl.Symbol
        self.SetWarmUp(50)   
        self.window = RollingWindow[TradeBar](5)
        self.SetBenchmark('AAPL')
        
        self.tol = 1.001
        self.lon = False
        
        
        
        self.shortSMA = self.EMA(self.symbol,9,Resolution.Minute)
        self.medSMA = self.EMA(self.symbol,21,Resolution.Minute)
        self.lonSMA = self.EMA(self.symbol,50,Resolution.Minute)
        
        self.Schedule.On(self.DateRules.EveryDay(self.symbol),
                 self.TimeRules.BeforeMarketClose(self.symbol, 1),
                 self.EveryDayBeforeMarketClose)
        self.Securities["AAPL"].FeeModel = ConstantFeeModel(0)
        
        
    def OnData(self, slice):
        
        if self.IsWarmingUp:
            return
    
        if slice.Bars.ContainsKey(self.symbol) and (slice[self.symbol] is not None):
            self.window.Add(slice[self.symbol])
        
        if self.window.IsReady and (self.window[0] is not None):
            self.Log(str(self.Time)+str(slice[self.symbol])+str(" ")+str(self.window[0].Open))
            
            firstOpen = self.window[3].Open
            firstClose = self.window[3].Close
            firstVol = self.window[3].Volume
            
            secondOpen = self.window[2].Open
            secondClose = self.window[2].Close
            secondVol = self.window[2].Volume
            
            thirdOpen = self.window[1].Open
            thirdClose = self.window[1].Close
            thirdVol = self.window[1].Volume
            
            price = self.window[0].Open
            
        else: 
            self.Debug(str("No data on window..."))    
            return
        
        if not self.Securities["AAPL"].HasData: return
            
        if (not self.Portfolio.Invested) and (price > self.shortSMA.Current.Value * self.tol ) and (self.shortSMA.Current.Value > self.medSMA.Current.Value) and self.lon == False:
            if (firstOpen < firstClose) and (self.window[4].Open >= self.window[4].Close):
                if firstClose <= secondOpen <= secondClose :
                    if  (secondClose <= thirdOpen < thirdClose) and ((secondVol > thirdVol and firstVol > thirdVol and secondVol < firstVol) or (secondVol > thirdVol and firstVol > thirdVol and secondVol > firstVol) or (((firstVol+secondVol)/2) <  (firstVol+thirdVol)/2)):
                        if price >= thirdClose :
                            
                            num_shares = int(self.CalculateOrderQuantity(self.symbol, 1))
                            self.MarketOrder(self.symbol,num_shares)
                            self.purch = price
                            self.lon = True
                            self.Debug(str(self.Time)+str(slice[self.symbol])+str(" Buy @")+str(price))
                            
                        
        if self.Portfolio.Invested or self.lon == True:
            if self.purch < self.window[0].Close:
                self.SetHoldings(self.symbol,0)
                self.Debug(str(self.Time)+str(slice[self.symbol])+str(" Profit @ ")+str(price))
                self.lon = True
                
                
    
    def EveryDayBeforeMarketClose(self):
        if self.Portfolio.Invested:
            self.SetHoldings(self.symbol,0)
            self.Debug(str(self.Time)+ str(" End of Day Close"))
        self.lon = False