Hi,

I'm new to QC and get my first experiences with Phyton. Now i'm trying to implement a simple stop loss via stop order to my algo. I buy the assets via SetHoldings in OnData.

Then I want to add a stop order in the OrderEvent:

    def OnOrderEvent(self, event):
           
           self.AveragePrice = self.Portfolio[event.Symbol].AveragePrice
           self.StopMarketOrder(event.Symbol, -self.Portfolio[event.Symbol].Quantity, self.AveragePrice*0.8)

The backtest with this code is not possible: It doesnt bring an compiler error etc but it crashes. The backtest starts and cant be finished. Is there an referencing problem here?

 

Thanks for your help, Chris