Hi - I'm looking for some help consolidating 1 minute bars into 5 minute bars (i.e. I want to run my existing strategy based off 5 min chart rather than the 1 minute chart). I'm new to coding, apologies if this is a bit basic.
I have tried looking up simialr discussions similar questions and tried the code suggested in multiple posts but nothing works and I'm very lost.
I've attached a backtest of a working algo with 1 min bars. How can I make this trade based on 5 min bars rather than one minute bars?
Based on my understanding, I need to add the below;
Add to Initialize
self.Consolidate("SPY", timedelta(minutes=5), self.OnDataConsolidated)
Add new function
def OnDataConsolidated(self, bar):
pass
What else would I need to do to get my algo to trade based of 5 minute bars?
Thanks
Vladimir
Ivanc
It's not clear why you need to use 5-minute bar data. The first 30 minute range will be the same whether we calculate it on 1 minute bar data, 5 minute bar data, or 30 minute bar data.
There are other ways to reduce trade frequency.
Mcdawgzy
Vladimir
For this algorithm yes it doesn't change the opening range but let's say I was to trade method way using 20 period high/lows rather than the opening range. How can I make it so that I can easily change the period between different time frames? For example use 1 min time frame (20 min period high/low), 5 min time frame (100 min high/low) etc?
Vladimir
Ivanc
To change the range calculation period from 30 minutes to 20 minutes or 100 minutes, there is no need to use the 5-minute bar data.
Mcdawgzy
@vladimir_2 it's not the opening range I want to chnage - I want to trade based of 5 minute time frame
Vladimir
Ivanc
To trade once every 5 minutes, it is not necessary to use 5-minute bar data.
Mcdawgzy
Vladimir so how do I do it then?
Vladimir
Ivanc
My understanding is that you want to trade "Opening Range Breakout" no more than once every 5 minutes. Is this correct?
Mcdawgzy
Vladimir Can we just ignore the opening range breakout for a second - I'm trying to understand what I can do so that the code written is not specific to this algo. Let's say I have a bollinger band setup that buys when a 5 min candle reaches below the lower band, and sells when the 5 min candle reaches the upper band. What do I need to do with the consolidator to make this work?
Shaun Dawson
I'm sure this is a stupid question, but isn't this just a matter of moving the logic that you currently have on OnData() and moving it into OnDataConsolidated() instead? (After putting the Consolidate() call in Initialize, of course…)
Mcdawgzy
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!