Hello,
So after a few days of testing, we found that the RSI 2 and RSI 14 did not match the data on the TradingView servers, by a good amount each time. The types of RSI data seem to be very consistent within themselves, but inconsistent with the data on TradingView. We are using the SPY indicator, warming up and calling different types of RSI each time (Wilders, Linear Moving Average, Exponential, etc.) but nothing seems to quite work. Note that they all give very different results on the actual trading bot.
class RetrospectiveBlackBear(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019,4, 1)
self.SetEndDate(2021, 7 ,15)
self.SetCash(100000)
self.UniverseSettings.Resolution = Resolution.Daily
##Adds possible equities
self.symbols = [
self.AddEquity("SPY", Resolution.Daily).Symbol,
#self.AddEquity("AGC", Resolution.Daily, fillDataForward == False).Symbol,
#self.AddEquity("APPS", Resolution.Daily, fillDataForward == False).Symbol,
self.AddEquity("BIB", Resolution.Daily).Symbol,
self.AddEquity("BOIL", Resolution.Daily).Symbol,
self.AddEquity("BRZU", Resolution.Daily).Symbol,
self.AddEquity("CURE", Resolution.Daily).Symbol,
self.AddEquity("CWEB", Resolution.Daily).Symbol,
self.AddEquity("DRN", Resolution.Daily).Symbol,
self.AddEquity("EDC", Resolution.Daily).Symbol,
]
#Creates RSI2 list
self.rsiTwo = [self.RSI(x, 2, MovingAverageType.Exponential , Resolution.Daily) for x in self.symbols]
#Creates RSI14 list
self.rsiFourteen = [self.RSI(x, 14, MovingAverageType.Exponential, Resolution.Daily) for x in self.symbols]
#SetWarmUp 200 days in minute
self.SetWarmUp(250, Resolution.Daily)
"""
#Calculate Indicators Daily
for x in self.symbols:
self.Schedule.On(self.DateRules.EveryDay(x), self.TimeRules.BeforeMarketClose(x,15), self.UpdateIndicators())
"""
def OnData(self, data):
#self.Debug(str(self.Time) + "- RSI2 SPY: " + str(self.rsiTwo[0].Current.Value))
self.Debug(str(self.Time) + "- RSI14 SPY: " + str(self.rsiFourteen[0].Current.Value))
#self.Debug(str(self.Time) + "- SMA 5: " + str(self.smaFive[0].Current.Value))
#Checks if the variables were warmed up
if self.IsWarmingUp:
#self.Debug("IT IS NOT Warm enough")
return
for z in range(len(self.symbols)):
if not self.rsiTwo[z].IsReady:
return
#self.Debug("RSI2 list is " + str(self.rsiTwo))
This is the code that creates the list of RSI's based on the symbol list with all the stocks.
Thank you very much, hope you have a good day
Vladimir
Hi Invest Club,
I ran a QC RSI versus Talib RSI calculated on consolidated 'close' Flipped Rolling Window
and got a perfect match.
Louis Szeto
Hi Invest Club, Vladimir
Thank you for your input Vladimir!
The default moving average for RSI is MovingAverageType.Wilders, so it might the be the source of the differences. However, please note that an indicator value depends heavily on the input data. While TradingView uses raw price, LEAN is using adjusted price by default. You may add this line in initialize method to use raw prices for all equities (see docs):
When we develop indicators in Lean, we compare them with third-party software using the same data. The closing price must be exactly the same to get the exact results.
Best,
Louis Szeto
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.
Invest Club
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!