I have been using the following to find the most current RSI.:
self.rsi = algo.RSI(symbol, 14, MovingAverageType.Simple, Resolution.Daily)
If I wanted to know what the RSI was two days ago, how would I modify the above code to find what the RSI was two days ago?
Dario Teodori
Hi Lemuel,
The easiest way rather than keeping history manually in the OnData is to use a rolling window:
So when you are evaluating just make sure the window is ready.
Lemuel Mwangi
Dario,
I tried integrating your suggestion into an algorithm I am trying to work out. But I am getting an error that “Method had no Attribute to Current”. I am guessing I am missing something in tying the rolling window to Symbol-Data.
See attached Algo for what I tried so far
Fred Painchaud
Hi Lemuel,
In your RollingWindow, you store floats:
self.rsi_win = RollingWindow[float](3) #3 slots: current, yesterday's and day before yesterday
So you do not need “.Current.Value” like this:
today_rsi = symbol_data.rsi_win[0].Current.Value
You should just do this:
today_rsi = symbol_data.rsi_win[0]
and
yesterday_rsi = symbol_data.rsi_win[1]
and
day_before_yesterday_rsi = symbol_data.rsi_win[2]
Fred
Lemuel Mwangi
Hi Fred, I tried that and I get an error stating “algorithm has no reference ”Self"
Fred Painchaud
Hi Lemuel,
Sorry but did you use “Self” with a capital “S”? If so, it is “self” with a small “s".
If you used “self” with a small “s”, then that error is a bit weird. I would need a dump of the code throwing that error. “self” with a small “s” should be accessible pretty much everywhere except outside classes and their methods. Maybe in a “method” declared without a “self” parameter…
Cheers,
Fred
Lemuel Mwangi
I used low cap “s”
Lemuel Mwangi
This is what I have so far. The problem appears to be on the very last line. The backtest states there is no reference to “Current” in that last line so the backtest gives an error
Rubio Manhattan
Hi
It seems to me that you have two typos:
did you mean: “if not symbol_data.rsi.IsReady:” ?
2. line 69: self.rsi.Updated += lambda sender,updated: self.rsi_win.Add(self.rsi.Current.Value)
Rubio
Varad Kabade
Hi Lemuel Mwangi,
In the above snippet inside the SymbolData class we need to use:
Because algo.RSI() is a helper method to create the rsi indicator object, not an instance of the RSI indicator; here in our case it is self.rsi.
Alternatively we recommend using the IndicatorExtensions.Of method refer to the following code snippet:
Here the self.rsi_2 refers to the indicator delayed by 2 days. Refer to the following doc for more information.
Best,
Varad Kabade
Lemuel Mwangi
I tried the suggestions above but still getting an error, won't even run a backtest (I guess I am not that savvy when it comes to coding). Is anyone willing to edit my also about such that it runs a backtest?
Varad Kabade
Hi Lemuel,
Please find a working backtest attached after removing the bugs from the above snippet.
Best,
Varad Kabade
Lemuel Mwangi
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!