Back

Easy Indicator History

It is common to keep track of historical values for various things. Sometimes we need to keep track of the last n bars of data, or sometimes we want to keep track of the last n values for an indicator. This is typically accomplished using a RollingWindow<T> and manually adding the values to the rolling window. In this algorithm, I've defined a HistoryTracker helper class which can make tracking the history of consolidators and indicators a one liner in Initialize!

This works by binding to the event handler on the indicator or consolidator and updating the rolling window from that!

Have a peek and let me know what you guys think!
Update Backtest






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.



Hi Michael, Thanks for this contribution.
Would also be nice to have a way to pass to your class a list of tradebar (below) that returns an IndicatorHistory without the need for OnData, so that you can have all the indicator past history in the initialize.

List tradeBarHistory = History(Symbol, TimeSpan.FromDays((this.StartDate - HistoryStartDate).Days), resolution).ToList();
0

You can take the result of the history request and pump it directly into your indicator:foreach (var tradeBar in tradeBarHistory) {
myIndicator.Update(tradeBar.EndTime, tradeBar.Close);
}
0

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.


Hi Michael,

Your easy history of indicator tracking method is very handy.  I could not figure out syntax needed to add stochastic.  Can you please help ?

Following is what I tried.

                Stochastic sto = STO(sec.Symbol, 14, 1, 1, Resolution.Hour);
                RollingWindow<IndicatorDataPoint> historySto = HistoryTrackerImpl.Track(sto, 3);

0

Update Backtest





0

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.


Loading...

This discussion is closed