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)
Louis Szeto
Hi William
The log result of LEAN matches TradingView's data (see attached image). There might be a very slight discrepancy for few pips as data wrapping. Note that 00:01:00 in LEAN is the bar receiving time, so it represents 00:00:00 in some other sources.
Best
Louis Szeto
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Will Chau
The problem turns out to be my incorrect time setting on tradingview. Thank you so much for you help!!
Will Chau
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!