Hi All! I am building a strategy with both hourly data, 30 mins data and 5 mins data of NQ future. However, I am not sure how to consolidate different timeframe on the same symbol. Below is what I did:
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_symbol = sorted(contract_symbols, key=lambda symbol: symbol.ID.Date)[0]
self.nq_1hour = self.AddFutureContract(self.contract_symbol, Resolution.Hour).Symbol
self.nq_half_hour = self.AddFutureContract(self.contract_symbol, Resolution.Minute).Symbol
self.Consolidate(self.nq_half_hour, timedelta(minutes=30), self.ThirtyMinuteBarHandler)
self.nq_5min = self.AddFutureContract(self.contract_symbol, Resolution.Minute).Symbol
self.Consolidate(self.nq_5min, timedelta(minutes=5), self.FiveMinuteBarHandler)
def FiveMinuteBarHandler(self, consolidated):
self.Debug(f"{self.Time}|FiveMinuteBarHandler fired! ")
def ThirtyMinuteBarHandler(self, consolidated):
self.Debug(f"{self.Time}|ThirtyMinuteBarHandler fired! ")
but i have the following error message:
Runtime Error: For Symbol MNQ15U23 can not consolidate bars of period: 00:30:00, using data of the same or higher period: 01:00:00 in PeriodCountConsolidatorBase.cs:line 159
I am using Minute data to consolidate to 30 mins and 5 mins so I am not sure what the problem is.
Mia Alissi
The error message you're seeing is due to the fact that you're trying to consolidate a higher resolution data (Hourly) into a lower resolution (30 minutes). In your code, you're adding the same future contract with different resolutions:
Then, you're trying to consolidate the minute resolution data into 30 minutes:
This is causing the error because you cannot consolidate a higher resolution data into a lower resolution.
To fix this, you should add the future contract with the lowest resolution you need (in this case, minute), and then consolidate to the higher resolutions. Here's how you can do it:
In this way, you're consolidating the minute data into 5 minutes, 30 minutes, and 1 hour respectively.
Remember to define the
OneHourBarHandler
method to handle the consolidated 1-hour data:For more information on data consolidation, you can refer to the QuantConnect documentation.
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.
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!