Disclaimer: I'm a beginner

Hey, I've been working on this algorithm, that trades BTC (so far) based on MFI. When the MFI for last 3 hours is greater or equal to 100 and the last candle is upward trending it should submit firstly a short order and then long after hitting the short stop loss.

The main problem I see right now is that the algorithm submits orders when the MFI is not ≥= 100. I compared the entries to the MFI data on BTC and from what I can see, the entries are completely different from the times MFI hits 100.

I tried various things, but I can't seem to figure out a solution.
Thank you!

PS: This is only a part of the code, that which I thought is the most relevant.

 class BTCTradingBot(QCAlgorithm):
    def Initialize(self):
        # add MFI indicator; hour resolution
        self.btc_money_flow = self.MFI(self.tick, 3, Resolution.Hour)
        # history data to check if the candle is upward or downward trending
        self.close_price_history = RollingWindow[float](4)
        self.open_price_history = RollingWindow[float](4)
    def OnData(self, data):
        self.short_order = None
        self.long_order = None
        # history data to check if the candle is upward or downward trending
        if data.ContainsKey(self.tick):
            previous_close = self.close_price_history[0]
            previous_open = self.open_price_history[0]
            self.Debug("// Setting rolling windows -- working")
        if (self.btc_money_flow.Current.Value >= 100) and (previous_close > previous_open):			
            #SHORT ORDER
            self.short_order = self.StopMarketOrder(self.tick, -0.1, self.Securities[self.tick].Close - self.Securities[self.tick].Close * 0.005, "Short order")
            self.short_id = self.short_order.OrderId
            #Stop loss for short order 
            if self.close_price_history[0] >= (self.close_price_history[1] + self.close_price_history[1] * 0.003):
                # self.trailing_sl_short = self.MarketOrder(self.tick, 0.1, "Short order stop loss")
                self.trailing_sl_short = self.LimitOrder(self.tick, 0.1, self.Securities[self.tick].Close + self.Securities[self.tick].Close * 0.003, "Short order stop loss")
                self.Debug("// Short stop loss -- working")
            #LONG ORDER
            if self.trailing_sl_short.Status == OrderStatus.Filled:
                self.long_order = self.StopMarketOrder(self.tick, 0.1, self.Securities[self.tick].Close, "Long order")
                self.long_id = self.long_order.OrderId
                #Stop loss for long order
                if self.close_price_history[1] >= (self.close_price_history[1] * 0.005):
                    # self.trailing_sl_long = self.MarketOrder(self.tick, -0.1, "Long order stop loss")
                    self.trailing_sl_long = self.LimitOrder(self.tick, -0.1, self.Securities[self.tick].Close * 0.005, "Long order stop loss")
                    self.Debug("// Long stop loss -- working")
            #For short orders
            if  (self.short_order in locals()) or (self.short_order in globals()) and (self.short_order.Status == OrderStatus.Filled):
                self.short_fill_time = self.Time
                self.Debug("// Short time based stop loss -- working")
            #For long orders
            if (self.long_order in locals()) or (self.long_order in globals()) and (self.short_order.Status == OrderStatus.Filled):
                self.long_fill_time = self.Time
                self.Debug("// Long time based stop loss -- working")