Hey all,
I'm new here so forgive me if this is a stupid question. I'm trying to port over some homemade algorithms to QuantConnect. My algorithms always worked with minute bars, and they re-evaluated every second, adding to a minute bar even if we didn't have full data for that minute.
For example: If we only had 20 seconds of data for the current minute. The current minute bar would have the high/low/mark/volume/etc for those 20 seconds of data.
I've looked into consolidators but it seems like they only consolidate data once an entire minute/hour/etc has passed. Does anyone know of a simple way to accomplish a running consolidation of the current bar?
Thanks in advance.
Rahul Chowdhury
Hey Brandon,
For any bar which has not been fully consolidated yet, you can access its consolidated value up to that time. We can do this using
// Consolidated bar up to current time _bar = _hour.WorkingData; where BaseData _bar; IDataConsolidator _hour;
Best
Rahul
Brandon McAlees
Thanks Rahul,
For those wondering, it looks like you need to create a consolidator for each symbol you intend on trading. I added this code to my "Initialize" function.
var symbols = new List<string>() { "BA", "MSFT" }; foreach (var symbol in symbols) { AddEquity(symbol, Resolution.Second); var consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(1)); _currentBar[symbol] = consolidator; //bind event handler to data consolidated event. consolidator.DataConsolidated += EveryMinute; //register the consolidator for data. SubscriptionManager.AddConsolidator(symbol, consolidator); }
Brandon McAlees
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!