TickConsolidator(100) will create a TradeBar from 100 ticks.
How does TickConsolidator (or AggregateBar) know when it has 100 ticks and it needs to create a new TradeBar?
I've looked at the TickConsolidator (and AggregateBar) code and I don't see how it knows when it is done aggregating the current bar after 100 ticks and creates a new TradeBar on the next tick.
I do see the maxCount variable but I don't see it being used anywhere within TickConsolidator. Where is the tick counter?
Why am I asking? I want to calculate TradeBar.Open to be the average of all prices from the first 50 ticks (instead of the first tick of the trade bar). And calculate the TradeBar.Close to be the average of all prices from the last 50 ticks (instead of the last tick of the trade bar).
So then, if N= 100 then
TickConsolidator(N)
TradeBar.Open = Average of all Tick Prices from the first N/2 ticks.
TradeBar.Close = Average of all Tick Prices from the last N/2 ticks.
Alexandre Catarino
Hi Michael Bloomfield ,
For this particular case where the open and close is a mean of x prices, I would suggest using a rolling window of 100 ticks:
_rollingWindow = new RolllingWindow<Tick>(100);
when the _rollingWindow.IsReady is true, you can create the TradeBar, and reset the RollingWindow:
if (_rollingWindow.IsReady) { var first = _rollingWindow[99]; var last = _rollingWindow[0]; var prices = _rollingWindow.Select(x => x.Value).ToList(); _tradeBar = new TradeBar { Symbol = first.Symbol, Time = first.Time, EndTime = last.Time, Close = prices.GetRange(0, 50).Sum(), High = prices.Max(), Low = prices.Min(), Open = prices.GetRange(50, 99).Sum(), }; _rollingWindow.Reset(); }
Michael Bloomfield
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!