Hi,
a) Other than using RollingWindow and storing the TradeBar in a RollingWindow, is their any other way of accessing previous TradeBar values?
b) Is the function OnData( TradeBars datas ), called only at bar close or at every tick? If at every tick, how do we detect that the bar has closed.
Regards
Vivek
Alexandre Catarino
a) No, there is no other way using the API. However, we can use C# List, Queue, Stack, etc...
b) OnData(TradeBars data) is an event handler fired when bar(s) is(are) closed.
Alexandre Catarino
Let me correct my previous answer.
You can access past values with a History request.
Please checkout the docs on Historical Data section:
// Request history for specific symbol, default to AddSecurity resolution. IEnumerable<TradeBar> bars = History("SPY", TimeSpan.FromDays(7)); // Request history for specific symbol, at specific resolution. IEnumerable<TradeBar> bars = History("SPY", TimeSpan.FromDays(7), Resolution.Minute); //Get last 14 bars of SPY, default to AddSecurity resolution. //Note you can't get "14 ticks" -- getting a specific number of bars only applies to TradeBar data. IEnumerable<TradeBar> bars = History("SPY", 14); //Get last 14 bars of SPY, at specific resolution. IEnumerable<TradeBar> bars = History("SPY", 14, Resolution.Minute); // Get history for all tickers we're subscribed to, at their native resolution IEnumerable<Slice> slices = History(TimeSpan.FromDays(7)); // Get history for all tickers we're subscribed to, at a specific resolution IEnumerable<Slice> slices = History(TimeSpan.FromDays(7), Resolution.Minute);
Please note that it may be more efficient to keep a record of past values than making a History request frequently (e.g. every minute).
Paranjay Paresh Desai
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!