Indicators With Custom Data -- Simple!

Here's a simple example that will work with any type of custom data. What we're doing here is importing some Quandl Yahoo data (YAHOO/INDEX_SPY), and then creating a MACD indicator on the closing prices (alias is Value).

Fist we add our daily Quandl data
AddData(SPY_QuandlCode, Resolution.Daily);

Then we create our MACD indicator with a fast period of 72, a slow period of 189, and a signal period of 9
macd = new MovingAverageConvergenceDivergence("MACD", 72, 189, 9, MovingAverageType.Exponential);

Then there's this line.
var quandlIdentityConsolidator = new IdentityDataConsolidator();
What this line does is create a consolidator for our Quandl data. Consolidators are the objects used to push data from the engine into the indicators. These allow for aggregation and transformation of the data (imagine aggregating small bars into larger bars). See DataConsolidation example for more information.

The IdentityDataConsolidator is one that does no aggregation and no transformation, it simply pipes everything through. So this will cause our daily data to just get forwarded to our MACD indicator with the help of the following registration line
RegisterIndicator(SPY_QuandlCode, macd, quandlIdentityConsolidator, x => x.Value);

What this does is register the consolidator for automatic updates and configures the consolidator to pipe its output into our indicator. The final argument is what's called a selector. This 'selects' the Value property from our Quandl object, this is the value that will be sent into the indicator.
Update Backtest

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.


This discussion is closed