Back

Using built in indicators with custom consolidated tradebar sizes?

Hello all,
I have checked out the sample code for creating tradebars with custom sizes e.g. 5 mins, 4 hours etc. However I have not been able to figure out how to use these custom sized tradebars with Quantconnect's built in MACD and SMA rolling indicators.
Basically I want the equivalent of:
_sma200 = SMA(_symbol, 200, Resolution.FiveMinute);
_MACD = MACD(_symbol, 12, 26, 9, MovingAverageType.Simple, Resolution.FourHour);
And I want to be able to process these indicators in my main algorithm loop. The main loop would update once per minute but it's okay if the indicators themselves only get updated as often as their tradebar widths permit.
Can anyone offer a solution for this?
Thank you
Update Backtest








Hey Joseph! This is possible you'd just need to manually create and update the indicators. This is via the indicator.Update method.

When you use the "SMA" functions we create an indicator object, and register it to automatically get updates -- however it is possible to feed whatever data you like into an indicator class.
2

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.


Perfect, thank you Jared you're the best!
0

Hey Joseph. Since this is a common request we've added a shortcut for you! You can use a snippet like the following:_macd = new MovingAverageConvergenceDivergence(12, 26, 9);
RegisterIndicator("SPY", _macd, TimeSpan.FromMinutes(5));

You can also specify different fields other than close:_macd = new MovingAverageConvergenceDivergence(12, 26, 9);
RegisterIndicator("SPY", _macd, TimeSpan.FromMinutes(5), Fields.Open);

You can see what fields are available here.

The technique displayed by Jared is used under the hood in the RegisterIndicator method, but provides the ultimate flexibility.
2

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.


PS: Mike tells me I should use args.EndTime in the consolidator event :)
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.


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