Hi, I am new to quantconnect, trying to understand how does the consolidator works, what I want to achieve is to get H4 candle in forex market.
I use `consolidator` to consolidate hourly quotebar into 4 hour bar, it start to count number of hours from 00:00:00. However, the forex market opens at Sunday 5pm EST, the correct H4 cancdle should start counting from then.
How should I set the starting time of the consolidaator? Or may be the starting time of the algo?
Many thanks in advance!
Rahul Chowdhury
Hey Xiolei,
Consolidating data always begins at midnight. If there is no data available because that market is closed, the consolidator just wont update until the market opens.This solution allows you to consolidate data between 5pm Sunday and 5pm Friday (Forex Hours). You can set your consolidating period by changing the timedelta parameter in the CalenderInfo that is returned in CustomDaily.
from datetime import datetime, timedelta class QuantumHorizontalChamber(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 6, 15) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.AddForex("EURUSD", Resolution.Minute) # Custom monthly consolidator consolidator = QuoteBarConsolidator(self.CustomDaily) consolidator.DataConsolidated += self.CustomDailyHandler self.SubscriptionManager.AddConsolidator("EURUSD", consolidator) def CustomDaily(self, dt): '''Custom Monthly Func''' start = (dt if dt.hour > 17 else dt - timedelta(1)).date() start = datetime.combine(start, datetime.min.time())+timedelta(hours=17) return CalendarInfo(start, timedelta(1)) def CustomDailyHandler(self, sender, consolidated): '''This is our event handler Custom Daily function''' self.Log(f"{consolidated.Time} >> CustomDailyHandler >> {consolidated.Close}")
Best,
Rahul
LE
The above code has been very helpful to get a Forex day (17:00-17:00) consolidator working. I changed “dt.hour > 17" to “dt.hour >= 17”, otherwise it would report in at 18:00 after the first day.
However, I'm having difficulty getting the H4 timeframe to work. As far as I understood from the instructions, I changed CalendarInfo to:
But now it only reports in at 17:00 and 21:00. I'm not familiar with timedelta, what am I doing wrong?
Louis Szeto
Hi LE
If you wish to consolidate every 4 hours from a 1700 start forex day, we suggest consolidating the first bar till 1700 for once only with warm-up set, then set 4 hours on Calendar for the next consolidation repeatedly after every consolidation.
We've attached a multiple-forex-asset backtest for your reference, please check the comments inside as well to help understanding.
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.
LE
Thank you Louis! Much appreciated.
I was having a small issue where the bars were updated on the 02 minute, but by increasing the algorithm warmup to 72 hours, it was fixed.
Xiaolei
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!