Hello!

I am experiencing  an issue and which despite reading other posts related to timing of positions, can't solve by myself. I implement my strategy to open a mean reversion position, so if the price of the current bar is lower than the previous bar, then open a long position. It seems like I receive correct signals, however instead of executing orders immediately at the beginning of a new bar after receiving the signal, the strategy waits until the end of a new bar,
Just to clarify what I mean by an example: if Tuesday's bar is lower than Monday's, then order should be executed immediately at the beginning Wednesday's bar. Instead, the position is opened at the end of Wednesday's bar.

I attached screenshots of the problem. “Pair1 0D” is the price of the FX pair, which is printed at the end of the bar,
As you can see, despite receiving signal at 19:00:00 on 2021-3-10 with the closing price of the bar at 8.48112, the order was executed next day, at 19:00 on 2021-3-11 at the price of 8.4545. I compared historical prices and indeed, the price on the 11th of March declined, which could cause such divergence in opening prices. However why did the strategy wait until the end of the next day to execute the order?
 

I would be grateful for any tips/advices.

205171_1660836983.jpg205171_1660836993.jpg

from AlgorithmImports import *

class CustomIndexStrategy(QCAlgorithm):
    def Initialize(self):

        self.Pair_1_Multiplier = 9.5
        self.Pair_1 = "USDSEK"
        self.holdingDays = 1
        self.SetStartDate (2021, 3, 3) 
        self.SetEndDate(2022,5,24)
        self.SetCash(1000000)  
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        self.EURSEK = self.AddForex(self.Pair_1, Resolution.Daily, Market.Oanda)
        self.symbols = [self.Pair_1]
        self.prevPrices = { symbol : RollingWindow[QuoteBar](7) for symbol in self.symbols }
        self.ticketPair1 = None 

    def OnData(self,data):
        
        for symbol in self.symbols:
            if data.ContainsKey(symbol):
                self.prevPrices[symbol].Add( data[symbol] )

        if not all([ window.IsReady for window in self.prevPrices.values() ]):
            return
            
        Pair1_window = self.prevPrices[self.Pair_1]
        Pair1_3D = Pair1_window[3].Close        
        Pair1_2D = Pair1_window[2].Close
        Pair1_1D = Pair1_window[1].Close
        Pair1_0D = Pair1_window[0].Close

        if self.ticketPair1 is not None and self.UtcTime < self.ticketPair1.Time + timedelta(days=(self.holdingDays)):
            return

        if self.ticketPair1 is None and Pair1_0D > Pair1_1D :
            self.Log("Pair1 0D: " + str(Pair1_0D) +" Pair1 1D: " + str(Pair1_1D) + " Pair1 2D " + str(Pair1_2D)  +" Pair1 3D " + str(Pair1_3D))
            self.ticketPair1 = self.StopMarketOrder(self.Pair_1, -100000 * self.Pair_1_Multiplier, 1.03 * self.Securities[self.Pair_1].Close) 

        if self.ticketPair1 is None and Pair1_0D < Pair1_1D:
            self.Log("Pair1 0D: " + str(Pair1_0D) +" Pair1 1D: " + str(Pair1_1D) + " Pair1 2D " + str(Pair1_2D)  +" Pair1 3D " + str(Pair1_3D))
            self.ticketPair1 = self.StopMarketOrder(self.Pair_1, 100000 * self.Pair_1_Multiplier, 0.97 * self.Securities[self.Pair_1].Close)    

        if self.ticketPair1 is not None and self.UtcTime >= self.ticketPair1.Time + timedelta(days = self.holdingDays): 
            self.Liquidate()
            self.ticketPair1 = None