Hi, i have a problem updating all trailing stops for my portfolio.

First, the inital stop loss is made during the order event: 

   def OnOrderEvent(self, event):
        # fetch the order of the event
        
        #INITAL STOPLOSS
        order = self.Transactions.GetOrderById(event.OrderId)
        if order.Type == OrderType.Market and orderEvent.Status == OrderStatus.Filled:
          
            self.stopMarketTicket = self.StopMarketOrder(event.Symbol, -event.Quantity, event.FillPrice*0.90)

 

In the OnData part, i want to update the Stoploss as a Trailing stop like this:

#Trailing Stop################################################
       
        for kvp in self.Portfolio:   # loop through portfolio
          
            self.StockWatermark = -1 # init
            self.StockClosePrice = self.GetPrice(kvp.Key)
            
            if self.StockClosePrice > self.StockWatermark: #and not(self.stopMarketTicket == none):
                
                self.StockWatermark = self.StockClosePrice # set new watermark high for this stock
                updateFields = UpdateOrderFields()
                updateFields.StopPrice = self.StockWatermark * 0.8
                self.stopMarketTicket.Update(updateFields) ### 

 

How do I use an Array of “self.stopMarketTicket” for all stocks in my portfolio and use it in the OnData part?

Should i pass it through the function like  def OnOrderEvent(self, event, Array): , and same in Ondata  def OnData(self, data, Array) ?

Thanks for your help, Regards Chris