hi , i made this bot of the logic that when the price of crypto falls lower or equal to previous low price in candle stick it should buy and when the prices increases as high as previous high or just more than what it had bought , it should liquidate portfolio.

  • I am trading with USDTUSD pair .
  • Most of the time the price increases by 0.0001 and falls at roughly to 0.0001 in 5min bar.
  • i just want suggestion on how can i make my code more efficient or better than it's present condition.


# --------------------------
CRYPTO = "USDTUSD"; BAR = 5; 
# --------------------------

class CryptoConsolidator(QCAlgorithm):
     
    def Initialize(self):
        self.SetStartDate(2021, 4, 1)
        self.SetEndDate(2022,  4, 20)
        self.SetCash(1000) 
        self.crypto = self.AddCrypto(CRYPTO, Resolution.Minute,Market.FTX).Symbol
        self.Consolidate(self.crypto, timedelta(minutes = BAR), self.BarHandler)
        self.entryPrice = 0
        self.nextEntryTime = self.Time
        self.period = timedelta(minutes = BAR) 


         
    def BarHandler(self, consolidated):
        self.Plot("USDTUSD", self.crypto, self.Securities[self.crypto].Price)
        
    def OnData(self, data):
        
        hist = self.History(self.crypto , timedelta(BAR), Resolution.Hour)#365
        low = min(hist["low"])
        high = max(hist["high"])
        
        
        if self.IsWarmingUp or not (self.nextEntryTime <= self.Time): return
        price = float(self.Securities[self.crypto].Close)
        
        if not self.Portfolio[self.crypto].Invested:
            if  price  < low :
                self.SetHoldings(self.crypto, 1.00)
                #self.entryPrice = price

        elif self.Portfolio[self.crypto].Invested:
            if  price >= high :
                self.Liquidate(self.crypto, "Take Profit")
                #self.entryPrice = price

        self.nextEntryTime = self.Time + self.period