I want to test some strategies on 5 min future data. After reading a few thread, I come up with code below to have 5 min bar. But when I print the Close price of it. It doesnt match the one on tradingview.  (see comparison below)

Tradingview uses data from CME, so I dont think the problem is caused by different data source. I see no spread on tradingview,  so should also have nothing to do with value between tradeBar and quoteBar either. 

I have no idea why the data doesnt match with the 1 min or 5 min chart close price.

Does anyone has any idea?

Thx in advance.

log result:
2021-08-31 00:01:00 symbol : ES17U21 and expiry : 2021-09-17 13:30:00
2021-08-31 00:01:00 close price : 4530.875 and open price : 4530.625

tradingview 1 minute(close price) :
4538  at 00:00:00
4539.5 at 00:01:00

tradingview 5 minute(close price) : 
4537.75 at 00:00:00
4537 at 00:05:00

 

class UncoupledVentralPrism(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 8, 31)
        self.SetEndDate(2021, 8, 31)
        self.SetCash(100000)
        
        future = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Minute)
        future.SetFilter(timedelta(0), timedelta(180))
        self.Consolidate(future.Symbol, timedelta(minutes=5), self.customBarHandler)

        self.macd = self.MACD(future.Symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute)
        self.macd.Updated += self.macdUpdated
        self.macdWindow = RollingWindow[IndicatorDataPoint](10)
        self.RegisterIndicator(future.Symbol, self.macd, timedelta(minutes=5))
        self.tradeBarWindow = RollingWindow[QuoteBar](10)
        
        self.currentDate = 0
        self.currentMinute = 0

    def OnData(self, data):
        if self.currentMinute == self.Time.minute:
            return 
            
        for chain in data.FutureChains:
            contracts = [contract for contract in chain.Value]
            self.Debug("------------")
            sorted_contracts = sorted(contracts, key=lambda x: x.Expiry)
            for c in sorted_contracts:
                self.Debug("symbol : {} and expiry : {}".format(c.Symbol.Value, c.Expiry))
                self.Debug("close price : {} and open price : {}".format(data[c.Symbol].Close, data[c.Symbol].Open))
                
            if len(sorted_contracts) == 0:
                self.Debug("nothing")
        
        self.currentMinute = self.Time.minute
        
    def customBarHandler(self, bar):
        self.tradeBarWindow.Add(bar)
        
    def macdUpdated(self, sender, updated):
        self.macdWindow.Add(updated)