I’m using a custom consolidator for 30 minute bars, so I need to fetch history on 30minute resultion, to update the consolidator with the correct tradebars (ie: the correct OHLC values.)
Whats the best way to do this? It seems I am restricted to fetching history for only the main resolutions (daily, minute, etc). Please see to the code snippet below to see what I've tried.
Thanks in advance
history = algorithm.History(symbol, barCount, TimeSpan.FromMinutes(30)) # error
history = algorithm.History(symbol, barCount, timedelta(minutes=30)) # error
history = algorithm.History(symbol, barCount, Resolution.Minute) # no error, but isn’t what i need
for index, row in history.loc[symbol].iterrows():
tradeBar = TradeBar()
tradeBar.Close = row['close']
tradeBar.Open = row['open']
tradeBar.High = row['high']
tradeBar.Low = row['low']
tradeBar.Volume = row['volume']
tradeBar.Time = index
tradeBar.Symbol = symbol
self.consolidator_30min.Update(tradeBar)
Derek Melchin
Hi .ekz.,
To retrieve the correct amount of bars, we can use
history = algorithm.History(symbol, barCount * 30, Resolution.Minute)
If this solution doesn't solve the issue, attach the full notebook so we can further assist.
Best,
Derek Melchin
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.
.ekz.
Thanks for the response Derek,
Unfortunately this doesn't solve the problem. This would give me candles (bars) for minute data. What I need is 30-Minute bars. These cannot be substituted with thirty 1-Minute bars. The bars are different, with different OHLC values.
Hopefully this is more clear. Do you know if it is possible?
Derek Melchin
Hi .ekz.,
We can gather the consolidated 30-minute TradeBars when the consoidation handler is called. In the consolidation handler, we can add the consolidated bar to a RollingWindow. To turn the RollingWindow into a DataFrame, we can use the PandasConverter.
See the attached backtest for reference.
Best,
Derek Melchin
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.
.ekz.
Follow up question: does this mean that, for indicators of custom resolutions (like 5 min, 30 min), I will need to use a consolidator + rollingwindow to calculate their values?
eg: To calculate the ATR for the past twenty 30-Minute bars, I need to set up a consolidator (to update every 30 min) and, in a consolidation handler, store the last twenty consolidated bars in a twenty period rolling window, and finally calculate my ATR manually.
Is this correct?
Derek Melchin
Hi .ekz.,
Yes, you are correct if you want to use your implementation of ATR.
Best,
Derek Melchin
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.
.ekz.
Thanks.
.ekz.
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!