Hello,
I am trying to filter stocks based on RSI values and some fundamental values.
I think I was able to find some values but not sure about accuracy.
My questions -
- I was getting multiple RSI values as 0 or 100 which I was not sure is correct. Is MovingAverageType.Wilders correct way declaration for RelativeStrengthIndex? any mistakes that you can help me with in my Algo?
- Apart from current RSI I want to compare it with RSI from previous day. So basically I want to check if RSI moved from <30 to >30 and then filter such stocks. Can you please guide me
Ray Trader
I think I was able to get my answer here by calculating the rollingwindow RSI calculation from coarse selection to onsecuritieschanged and onData processing
Derek Melchin
Hi Ray,
Great start. Here are some answers:
(1) RSI values will be 0 when the RSI indicator is not finished warming up. We can check if it is ready for use by checking the `.IsReady` property. Yes, we can use `MovingAverageType.Wilders` for the RSI indicator. We have several other types we can use too. They are all listed in our documentation.
(2) As was mentioned above, we can check historical RSI values by setting up a RollingWindow. Typically, we do not want to filter our universe by the RSI value as its calculation requires a `History` call to warm up during each universe selection call. In this situation, we can filter our universe by dollar volume and price. Then with each new security, we can setup a SymbolData object to track the RSI value and signal the RSI crossovers.
See the attached backtest for an example algorithm that buys when the RSI crosses above 30 and holds for a one day. Note that removed the SetWarmUp call has been removed as universe selection is not included in warm up. Also note that the RSI alpha model has been replaced by one that will hold our SymbolData objects.
Best,
Derek Melchin
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.
Ray Trader
Hi Derek,
Thank you for the code and demo.
I see you have used the Insights to pass in the crossover.
Question is - Is it better to use the AlphaModel for technical signals or if it may be handled in onData of main algorithm?
For example below I did the same example but in onData() method mainly because using the indicators helper method (self.indicator(symbol, timepeeriod, etc, etc)) is much easier compared to the other way RelativeStrengthIndex(symbol, Timeperiod) and then using the update method.
What changes I may experience by calculating the indicator values in onData vs manual .Update(time, value) ?
Thank you
Derek Melchin
Hi Ray,
The strategy logic can go in either the OnData or Update method. Both methods can be implemented to produce the same trades and equity curve. However, we recommend users favor the Update method as it takes advantage of the Algorithm Framework design. By placing the code in Update, we encapsulate the signal processing logic into its own class instead of it being embedded within the algorithm class.
In addition to the indicator calculations, notice how in the backtest code above, position sizing is determined in OnData. By adhering to the Algorithm Framework, this logic would also be removed from the algorithm class and put into a portfolio construction model.
Best,
Derek Melchin
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.
Ray Trader
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!