Hello,

I'm trying to figure out why the RSI is vastly different from trading view on the 5 minute timeframe. I understand there may be differences in data but this wildly different, ranging from 5, 10, even 20 points different. From what I can see I'm registering the indicator correctly with automatic updates. But when I log the values below, they are completely off.

Eg: July 18 14:00:00 (EST)

TradingView: 70.98

Log: 62.18

For reference, the RSI only became wildly different when I started to consolidate bars to 5 minutes. The 1 minute timeframe matched nearly perfectly with TradingView.

  1. from AlgorithmImports import *
  2. from datetime import datetime, date
  3. class AlertLightBrownHyena(QCAlgorithm):
  4. def Initialize(self):
  5. self.ticker = 'SPY'
  6. self.startingCash = 100000
  7. self.startDate = '2023-06-01'
  8. self.endDate = '-'
  9. # Equities
  10. self.resolution = Resolution.Minute
  11. self.equity = self.AddEquity(self.ticker, self.resolution)
  12. self.equity.SetDataNormalizationMode(DataNormalizationMode.Raw)
  13. # Backtesting
  14. self.SetStartDate(datetime.fromisoformat(self.startDate))
  15. self.SetEndDate(datetime.fromisoformat(self.endDate)) if self.endDate != '-' else self.SetEndDate(datetime.now())
  16. self.SetCash(self.startingCash)
  17. self.SetTimeZone("America/New_York")
  18. self.SetBenchmark(self.equity.Symbol)
  19. self.SetWarmUp(100)
  20. # Consolidators
  21. self.consolidator = self.Consolidate(self.equity.Symbol, timedelta(minutes=5), self.OnFiveMinData)
  22. # Indicators
  23. self.rsi = RelativeStrengthIndex(14, MovingAverageType.Simple)
  24. self.RegisterIndicator(self.equity.Symbol, self.rsi, self.consolidator)
  25. self.rsiSMA = IndicatorExtensions.SMA(self.rsi, 14)
  26. def OnFiveMinData(self, data):
  27. self.Log(f"Close: {round(data.Close, 2)}, RSI: {round(self.rsi.Current.Value, 2)}, RSI SMA: {round(self.rsiSMA.Current.Value, 2)}")
+ Expand

Author

Joshua Woelfel

July 2023