I tried to write a function that blocks new trades being placed for 30 minutes after a stop or take profit is hit, as often the trade criteria are still met immediately after exiting a position on shorter time frames, which can create a terrible loop of repeated losses, or cause an entry near the end of a breakout after tp is hit. I was using a scheduled event every minute to check against the time of my most recent tickets, but I am not sure how to do that outside of OnOrderEvent, which is the logic I was piggypacking off of? Or if there is a simpler way that I am missing.? Obviously, this code does not run as ‘orderEvent.OrderId’ does not exist outside of OnOrderEvent

 

self.Schedule.On(everyday, self.TimeRules.Every(timedelta(minutes=1)), self.TradeBuffer)



def TradeBuffer(self):
    
        for symbol, data in self.symbolData.items():
            if data.stopmarketorderticket != None and data.stopmarketorderticket.OrderId == orderEvent.OrderId:
                if self.UtcTime >= (data.stopmarketorderticket.Time + timedelta(minutes=30)):
                    data.longTrade = True
                    
            if data.limitorderticket != None and data.limitorderticket.OrderId == orderEvent.OrderId:
                if self.UtcTime >= (data.limitorderticket.Time + timedelta(minutes=30)):
                    data.longTrade = True