Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
class FocusedMagentaHornet(QCAlgorithm):
    
    # THIS ALGORITHM FOCUSES ON 3 MAJOR SIGNALS FOR EXITING A TRADE and one trend indicator for allocating our portfolio:
        # Exiting a trade signal:
            # 1. Exiting a trade when the price goes above 5%
            # 2. Exiting a trade when the price goes above 2%
            # 3. Exiting a trade when the trailing stop loss is hit which is %10 of last highest close price 
        # Trend indicator:
            # 10 Day moving average
        
    # Order ticket for our stop order, Datetime when stop order was last hit
    # ADGI ORDER TICKET
    stopMarketTicketFirst = None
    stopMarketOrderFillTimeFirst = datetime.min
    highestFirstPrice = -1
    
    # CORZ ORDER TICKET
    stopMarketTicketSecond = None
    stopMarketOrderFillTimeSecond = datetime.min
    highestSecondPrice = -1
    
    def Initialize(self):
        
        #Brokerage model and account type:
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Cash)
        self.SetStartDate(2021, 2, 1)  # Set Start Date
        self.SetCash(170)  # Set Strategy Cash
        
        self.kpti = self.AddEquity("KPTI", Resolution.Daily)
        # stockOne.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.ego = self.AddEquity("EGO", Resolution.Daily)
        # stockTwo.SetDataNormalizationMode(DataNormalizationMode.Raw)
        
        self.kptiMomentum = self.MOMP("KPTI", 10, Resolution.Daily) 
        self.egoMomentum = self.MOMP("EGO", 10, Resolution.Daily)
        
        # INITIALIZE 50 HISTORY DATA  
        self.SetWarmUp(50)
        
    def OnData(self, data):
        if self.IsWarmingUp:
            return
        
        # 1. Plot the current Stock1 price to "Data Chart" on series "Stock 1 Price"
        self.Plot("Data Chart", "Stock 1 Price", self.Securities["KPTI"].Close) 
        
        # 2. Plot the current Stock 2 price to "Data Chart" on series "Stock 2 Price"
        self.Plot("Data Chart", "Stock 2 Price", self.Securities["EGO"].Close)
        
        if self.kptiMomentum.Current.Value > self.egoMomentum.Current.Value:
        
            if (self.Time - self.stopMarketOrderFillTimeFirst).days < 1:
                return
            if not self.Portfolio.Invested or self.Portfolio.Invested:
                if not self.Securities["KPTI"].Invested:
                    # Calculate the fee adjusted quantity of shares with given buying power
                    quantityFirst = self.CalculateOrderQuantity("KPTI", 0.8)
                    self.MarketOrder("KPTI", quantityFirst)
                    self.Debug(f"Quantity: {quantityFirst}")
                    self.stopMarketTicketFirst = self.StopMarketOrder("KPTI", -quantityFirst, 0.9 * self.Securities["KPTI"].Close)
            
                elif (self.Securities["KPTI"].Close > self.stopMarketTicketFirst.AverageFillPrice * 1.05) and (self.Securities["KPTI"].Close > self.highestFirstPrice):
        
                    #2. Plot the moving stop price on "Data Chart" with "Stock 1 Stop Price" series name
                    self.Plot("Data Chart", "Stock 1 Stop Price", self.highestFirstPrice * 0.9) 
                        
                    self.highestFirstPrice = self.Securities["KPTI"].Close
                    updateFields = UpdateOrderFields()
                    updateFields.StopPrice = self.highestFirstPrice * 0.9
                    self.stopMarketTicketFirst.Update(updateFields)
                    self.Debug("Highest Close Price for Stock 1: " +str(self.highestFirstPrice))
                    quantityFirst = self.CalculateOrderQuantity("KPTI", 0.8)
                    self.MarketOrder("KPTI", -((quantityFirst)/3))
                    self.Debug(f"Quantity: {-((quantityFirst)/3)}")
                    
                elif (self.Securities["KPTI"].Close > self.stopMarketTicketFirst.AverageFillPrice * 1.02) and (self.Securities["KPTI"].Close > self.highestFirstPrice):
        
                    #2. Plot the moving stop price on "Data Chart" with "Stock 1 Stop Price" series name
                    self.Plot("Data Chart", "Stock 1 Stop Price", self.highestFirstPrice * 0.9) 
                    
                    self.highestFirstPrice = self.Securities["KPTI"].Close
                    updateFields = UpdateOrderFields()
                    updateFields.StopPrice = self.highestFirstPrice * 0.9
                    self.stopMarketTicketFirst.Update(updateFields)
                    self.Debug("Highest Close Price for Stock 1: " +str(self.highestFirstPrice))
                    quantityFirst = self.CalculateOrderQuantity("KPTI", 0.8)
                    self.MarketOrder("KPTI", -((quantityFirst)/2))
                    self.Debug(f"Quantity: {-((quantityFirst)/2)}")
                    
                else:
                    if self.Securities["KPTI"].Close > self.highestFirstPrice:
                        self.highestFirstPrice = self.Securities["KPTI"].Close
                        updateFields = UpdateOrderFields()
                        updateFields.StopPrice = self.highestFirstPrice * 0.9
                        self.stopMarketTicketFirst.Update(updateFields)
                        self.Debug("Highest Close Price for Stock 1: " +str(self.highestFirstPrice))
        else:
            
            if (self.Time - self.stopMarketOrderFillTimeSecond).days < 1:
                return
            if not self.Portfolio.Invested or self.Portfolio.Invested:
                if not self.Securities["EGO"].Invested:
                    # Calculate the fee adjusted quantity of shares with given buying power
                    quantitySecond = self.CalculateOrderQuantity("EGO", 0.8)
                    self.MarketOrder("EGO", quantitySecond)
                    self.Debug(f"Quantity: {quantitySecond}")
                    self.stopMarketTicketSecond = self.StopMarketOrder("EGO", -quantitySecond, 0.9 * self.Securities["EGO"].Close)
                
                elif (self.Securities["EGO"].Close > self.stopMarketTicketSecond.AverageFillPrice * 1.05) and (self.Securities["EGO"].Close > self.highestSecondPrice):
                
                    #2. Plot the moving stop price on "Data Chart" with "Stock 2 Stop Price" series name
                    self.Plot("Data Chart", "Stock 2 Stop Price", self.highestSecondPrice * 0.9) 
                        
                    self.highestSecondPrice = self.Securities["EGO"].Close
                    updateFields = UpdateOrderFields()
                    updateFields.StopPrice = self.highestSecondPrice * 0.9
                    self.stopMarketTicketSecond.Update(updateFields)
                    self.Debug("Highest Close Price for Stock 2: " +str(self.highestSecondPrice))
                    quantitySecond = self.CalculateOrderQuantity(self.stockTwo, 0.8)
                    self.MarketOrder("EGO", -((quantityEGO)/3))
                    self.Debug(f"Quantity: {-((quantityEGO)/3)}")
                    
                elif (self.Securities["EGO"].Close > self.stopMarketTicketSecond.AverageFillPrice * 1.02) and (self.Securities["EGO"].Close > self.highestSecondPrice):
                
                    #2. Plot the moving stop price on "Data Chart" with "Stock 2 Stop Price" series name
                    self.Plot("Data Chart", "Stock 2 Stop Price", self.highestSecondPrice * 0.9) 
                        
                    self.highestSecondPrice = self.Securities["EGO"].Close
                    updateFields = UpdateOrderFields()
                    updateFields.StopPrice = self.highestSecondPrice * 0.9
                    self.stopMarketTicketSecond.Update(updateFields)
                    self.Debug("Highest Close Price for Stock 2: " +str(self.highestSecondPrice))
                    quantitySecond = self.CalculateOrderQuantity("EGO", 0.8)
                    self.MarketOrder("EGO", -((quantitySecond)/2))
                    self.Debug(f"Quantity: {-((quantitySecond)/2)}")
                    
                else:
                    if self.Securities["EGO"].Close > self.highestSecondPrice:
                        self.highestSecondPrice = self.Securities["EGO"].Close
                        updateFields = UpdateOrderFields()
                        updateFields.StopPrice = self.highestSecondPrice * 0.9
                        self.stopMarketTicketSecond.Update(updateFields)
                        self.Debug("Highest Close Price for Stock 2: " +str(self.highestSecondPrice))
                        
            
    def OnOrderEvent(self, orderEvent):
        
        if orderEvent.Status != OrderStatus.Filled:
            return
        
        if self.stopMarketTicketFirst is not None and self.stopMarketTicketFirst.OrderId == orderEvent.OrderId: 
            self.stopMarketOrderFillTimeFirst = self.Time
        else:
            if self.stopMarketTicketSecond is not None and self.stopMarketTicketSecond.OrderId == orderEvent.OrderId: 
                self.stopMarketOrderFillTimeSecond = self.Time