Hi All! I would like to get 5mins, 30mins and 1hour data of NQ future. My code is as below:
self.contract_symbol = Symbol.CreateFuture(Futures.Indices.MicroNASDAQ100EMini, Market.CME, datetime(2023,8,28))
continuous_future_symbol = Symbol.Create(Futures.Indices.MicroNASDAQ100EMini, SecurityType.Future, Market.CME)
contract_symbols = self.FutureChainProvider.GetFutureContractList(continuous_future_symbol, self.Time)
self.contract_symbol2 = sorted(contract_symbols, key=lambda symbol: symbol.ID.Date)[0]
self.contract_symbol = self.AddFutureContract(self.contract_symbol2, Resolution.Minute).Symbol
self.nq_5min = self.Consolidate(self.contract_symbol, timedelta(minutes=5), self.FiveMinuteBarHandler)
self.nq_half_hour = self.Consolidate(self.contract_symbol, timedelta(minutes=30), self.ThirtyMinuteBarHandler)
self.nq_1hour = self.Consolidate(self.contract_symbol, timedelta(hours=1), self.OneHourBarHandler)
def FiveMinuteBarHandler(self, consolidated):
self.Debug(f"{self.Time}|FiveMinuteBarHandler fired! ")
def ThirtyMinuteBarHandler(self, consolidated):
self.Debug(f"{self.Time}|ThirtyMinuteBarHandler fired! ")
def OneHourBarHandler(self, consolidated):
self.Debug(f"{self.Time}|OneHourBarHandler fired! ")
However, when I try to call the History function like below, i have an error message since nq_1hour, nq_half_hour and nq_5min are not symbol object:
hourly_data = self.History(self.nq_1hour, 100, Resolution.Hour, extendedMarketHours = False)
half_hour_data = self.History(self.nq_half_hour, 3000, Resolution.Minute, extendedMarketHours = False)
data = self.History(self.nq_5min, 3000, Resolution.Minute, extendedMarketHours = False)
But if i use self.History(
, 3000, Resolution.Minute, extendedMarketHours = False), i can only get unconsolidated data. May I know how can I get consolidated data of different timeframe?
Random
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!