Back

How to use indicator in helper class

According to the documentation here: 

https://www.quantconnect.com/docs/algorithm-reference/universes#Universes-Coarse-Universe-Selection

I should be able to use an indicator (I'm trying to get the RSI for the forex universe) in the __init__ function of a class outside of the main class entry point. This didn't seem possible to me and it seems it isn't possible. When I try to call RSI in this outside class it is undefined. Can anyone enlighten me on what the documentation is showing with regard to how you create this "SelectionData" class?

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.


Hi Chris,

The example 2 on the page you referred to is a good demonstration of using the SelectionData class. The abbreviated indicator methods (EMA, RSI) are helper methods within the QCAlgorithm. To use them outside of the QCAlgorithm class, you will need to pass the algorithm as a parameter to the outside class to access the helper methods.

However, a better way is to use the foundational classes, and you can find all the indicators here. For example, instead of calling EMA, you would call ExponentialMovingAverage in the SelectionData class as shown in example 2. Similarly, you would call RelativeStrengthIndex instead of RSI. Using the constructors this way will define the indicator and allow you to remove the consolidators used for automatic updates when the security is removed from the universe. 

Hope this helps!

1

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