Hi All,

When implementing a simple stop loss / profit take, and timed exit for a trade I am running into an issue where all three execute simultaneously. despite being restricted by conditions (see order screen cap).

Could someone explain to me why this is happening, and how to fix it? I have attached the backtest code. Thanks in advance!

class TradeStrategyTest(QCAlgorithm):
  
  def Initialize(self):
       self.SetStartDate(2021,3, 1)  #Set Start Date
       self.SetEndDate(2021,6,14)    #Set End Date
       self.SetCash(10000)           #Set Strategy Cash
       self.AddEquity("OCGN", Resolution.Minute)
       self.RSI1 = self.RSI("OCGN", 15)
       self.RSI2 = self.RSI("OCGN", 2)
       self.SetWarmUp(14)
       self.Securities["OCGN"].FeeModel = ConstantFeeModel(2.00)
   
       
       self.ticket = None # Flag for position status
       
   
  def OnData(self, data):
      
       if self.IsWarmingUp or not data.Bars.ContainsKey("OCGN") or not self.RSI1.IsReady or not self.RSI2.IsReady:
           return
   
   # Buy Conditions 
       if not self.Securities["OCGN"].Invested and self.ticket is None:
          
           if ((self.RSI1.Current.Value <=70 and self.RSI1.Current.Value >=20)):
               self.ticket = self.MarketOrder("OCGN", 1)  
               self.StopMarketOrder("OCGN", -1, self.Securities["OCGN"].Close* 0.95*0.99) 
               self.LimitOrder("OCGN", -1, self.Securities["OCGN"].Close*1.03)
    
               
       elif  self.Portfolio["OCGN"].Invested:       
               self.ticket is not None and self.UtcTime > self.ticket.Time + timedelta(minutes = 15)
               self.Liquidate()
               self.ticket = None
   
 

Order Screen Cap:

159988_1623786942.jpg