Overall Statistics
Total Trades
731
Average Win
1.45%
Average Loss
-0.81%
Compounding Annual Return
29.635%
Drawdown
26.000%
Expectancy
0.223
Net Profit
91.403%
Sharpe Ratio
1.311
Probabilistic Sharpe Ratio
61.152%
Loss Rate
56%
Win Rate
44%
Profit-Loss Ratio
1.78
Alpha
0.284
Beta
-0.085
Annual Standard Deviation
0.201
Annual Variance
0.04
Information Ratio
0.078
Tracking Error
0.305
Treynor Ratio
-3.08
Total Fees
$777.05
Estimated Strategy Capacity
$190000000.00
Lowest Capacity Asset
ROKU WO9FGTL2I89X
class UnicornLove(QCAlgorithm):
# This strategy will look at 3 days worth of price data
# If today's close price is higher than the last 2 day's high price....and
# The RSI is lower than 80
# We will setHoldings @ 50% and take profit after 6% in our favor. Stop loss at 2% loss.

    def Initialize(self):
        self.SetStartDate(2019, 1, 1)
        self.SetEndDate(2021, 7, 1)
        self.SetCash(100000)
        
        # Define custom set of stocks here:
        self.a = 'ROKU'
        self.b = 'FB'
        self.c = 'AMZN'
        self.d = 'GOOG'
        self.e = 'MSFT'
        self.StocksSetA = [self.a, self.b, self.c, self.d, self.e]
      
        self.AddEquity(self.a, Resolution.Daily)
        self.AddEquity(self.b, Resolution.Daily)
        self.AddEquity(self.c, Resolution.Daily)
        self.AddEquity(self.d, Resolution.Daily)
        self.AddEquity(self.e, Resolution.Daily)
        
        # Aim to benchmark against the S&P500 index
        self.SetBenchmark('SPY')
        
        # Adding an RSI indicator
        self.a_rsi = self.RSI(self.a, 14)
        self.b_rsi = self.RSI(self.b, 14)
        self.c_rsi = self.RSI(self.c, 14)
        self.d_rsi = self.RSI(self.d, 14)
        self.e_rsi = self.RSI(self.e, 14)
        
        # Create all the custom variables you will be using here
        self.a_initial_close = None
        self.a_yesterday_close = None
        self.a_today_close = None
        
        self.b_initial_close = None
        self.b_yesterday_close = None
        self.b_today_close = None
        
        self.c_initial_close = None
        self.c_yesterday_close = None
        self.c_today_close = None
        
        self.d_initial_close = None
        self.d_yesterday_close = None
        self.d_today_close = None        

        self.e_initial_close = None
        self.e_yesterday_close = None
        self.e_today_close = None
        
    def OnData(self, data):
        
        StocksA = self.StocksSetA
        
        # price = data[STOCKSYM].Close    /Open/High/Low/Volume
        
        for element in StocksA:
            # Sequence to capture the _close price for stock array number 0
            self.a_initial_close = self.a_yesterday_close
            self.a_yesterday_close = self.a_today_close
            self.a_today_close = data[StocksA[0]].Close
            
            # Sequence to capture the _close price for stock array number 1
            self.b_initial_close = self.b_yesterday_close
            self.b_yesterday_close = self.b_today_close
            self.b_today_close = data[StocksA[1]].Close
            
            # Sequence to capture the _close price for stock array number 2
            self.c_initial_close = self.c_yesterday_close
            self.c_yesterday_close = self.c_today_close
            self.c_today_close = data[StocksA[2]].Close
            
            # Sequence to capture the _close price for stock array number 3
            self.d_initial_close = self.d_yesterday_close
            self.d_yesterday_close = self.d_today_close
            self.d_today_close = data[StocksA[3]].Close
            
            # Sequence to capture the _close price for stock array number 4
            self.e_initial_close = self.e_yesterday_close
            self.e_yesterday_close = self.e_today_close
            self.e_today_close = data[StocksA[4]].Close
            
            
            if self.a_rsi.IsReady and self.b_rsi.IsReady and self.c_rsi.IsReady and self.d_rsi.IsReady and self.e_rsi.IsReady:
            
                # This is the test condition to ensure that we have at least 3 days worth of data before executing trades
                if self.a_initial_close == None or self.b_initial_close == None or self.c_initial_close == None or self.d_initial_close == None or self.e_initial_close == None:
                    return
                
                # Testing Code
                if not self.Portfolio[StocksA[0]].Invested and \
                self.a_today_close > (self.a_yesterday_close + self.a_initial_close) / 2 and \
                self.a_rsi.Current.Value <= 75:
                    self.SetHoldings(StocksA[0], 0.20)
                    self.a_entry_price = data[StocksA[0]].Close
                    
                if not self.Portfolio[StocksA[1]].Invested and \
                self.b_today_close > (self.b_yesterday_close + self.b_initial_close) / 2 and \
                self.b_rsi.Current.Value <= 75:
                    self.SetHoldings(StocksA[1], 0.20)
                    self.b_entry_price = data[StocksA[1]].Close
                    
                if not self.Portfolio[StocksA[2]].Invested and \
                self.c_today_close > (self.c_yesterday_close + self.c_initial_close) / 2 and \
                self.c_rsi.Current.Value <= 75:
                    self.SetHoldings(StocksA[2], 0.20)
                    self.c_entry_price = data[StocksA[2]].Close
                    
                if not self.Portfolio[StocksA[3]].Invested and \
                self.d_today_close > (self.d_yesterday_close + self.d_initial_close) / 2 and \
                self.d_rsi.Current.Value <= 75:
                    self.SetHoldings(StocksA[3], 0.20)
                    self.d_entry_price = data[StocksA[3]].Close                    

                if not self.Portfolio[StocksA[4]].Invested and \
                self.e_today_close > (self.e_yesterday_close + self.e_initial_close) / 2 and \
                self.e_rsi.Current.Value <= 75:
                    self.SetHoldings(StocksA[4], 0.20)
                    self.e_entry_price = data[StocksA[4]].Close
                    
               # I will close the position if the market moves 2% in the wrong direction
               # I will take profit after the market moves 6% in my favor
                if self.Portfolio[StocksA[0]].Invested:
                    if data[StocksA[0]].Close >= 1.06 * self.a_entry_price:
                       self.Liquidate(StocksA[0])
                    elif data[StocksA[0]].Close <= 0.98 * self.a_entry_price:
                        self.Liquidate(StocksA[0])
                
                if self.Portfolio[StocksA[1]].Invested:
                    if data[StocksA[1]].Close >= 1.06 * self.b_entry_price:
                       self.Liquidate(StocksA[1])
                    elif data[StocksA[1]].Close <= 0.98 * self.b_entry_price:
                        self.Liquidate(StocksA[1])
                        
                if self.Portfolio[StocksA[2]].Invested:
                    if data[StocksA[2]].Close >= 1.06 * self.c_entry_price:
                       self.Liquidate(StocksA[2])
                    elif data[StocksA[2]].Close <= 0.98 * self.c_entry_price:
                        self.Liquidate(StocksA[2])
                        
                if self.Portfolio[StocksA[3]].Invested:
                    if data[StocksA[3]].Close >= 1.06 * self.d_entry_price:
                       self.Liquidate(StocksA[3])
                    elif data[StocksA[3]].Close <= 0.98 * self.d_entry_price:
                        self.Liquidate(StocksA[3])
                        
                if self.Portfolio[StocksA[4]].Invested:
                    if data[StocksA[4]].Close >= 1.06 * self.e_entry_price:
                       self.Liquidate(StocksA[4])
                    elif data[StocksA[4]].Close <= 0.98 * self.e_entry_price:
                        self.Liquidate(StocksA[4])
        
    def OnEndOfAlgorithm(self):
        self.Debug('Total stock value is ' + str(self.Portfolio.TotalPortfolioValue))
        self.Debug('Total unrealized profit is ' + str(self.Portfolio.TotalUnrealizedProfit))