Vladimir  hi how can i compare the current price to the price on which i had bought BTC.

the code is same

 

# Rolling Window

# --------------------------
CRYPTO = "BTCUSD"; BARS = 2; 
# --------------------------

class CryptoConsolidator(QCAlgorithm):
     
    def Initialize(self):
        self.SetStartDate(2022, 5, 2)
        self.SetEndDate(2022, 5, 3)
        self.SetCash(1000) 
        self.crypto = self.AddCrypto(CRYPTO, Resolution.Minute, Market.FTX).Symbol
        self.window = RollingWindow[TradeBar](BARS)  
        self.Consolidate(self.crypto, Resolution.Minute, self.CustomBarHandler)
        

    def CustomBarHandler(self, bar):
        self.window.Add(bar)  
        
        
    def OnData(self, data):
        if not self.window.IsReady: return

        curr_close = np.array([self.window[i].Close for i in range(BARS)])[0]                     
        past_close = np.array([self.window[i].Close for i in range(BARS)])[1]  

        self.Plot(self.crypto, "curr_close", curr_close)
        self.Plot(self.crypto, "past_close", past_close)
        
        if not self.Portfolio[self.crypto].Invested:
            if curr_close <= past_close*0.999:
                self.SetHoldings(self.crypto, 1.00 )

        elif self.Portfolio[self.crypto].Invested:
            if curr_close >= past_close*1.001:
                self.Liquidate(self.crypto,"sell")