anandanand84 / technicalindicators

A javascript technical indicators written in typescript with pattern recognition right in the browser
MIT License
2.13k stars 550 forks source link

How many days closing price should be passed to calculate RSI(14) #239

Open kiransalian91 opened 3 years ago

kiransalian91 commented 3 years ago

Below I am passing 15 days closing price (oldest close price first).

const rsi = this.calculateRSI.calculate({
  period: 14,
  values: [  153.6, 146.65, 146.4, 147.5, 152.7, 154.45, 150.45, 149.55, 153.6, 161.85,  160.75, 159.0, 163.85, 163.25, 161.05 ]
});

I get response as below. console.log(rsi) // [58.67].

But actual RSI value which is displayed in Zeroda or TradingView is : 60.79.

Please help me if I am missing something here.

saru2020 commented 3 years ago

Yes, the calculations vary b/w tradingview & RSI in this lib. I suppose it is the duplicate of #216

marcusmota commented 2 years ago

the lib works, try to add more data to RSI, I think the values starts to match with the tv RSI with 100+ candles

saru2020 commented 2 years ago

@marcusmota thanks for the reply. Are you saying that the lib works only with 100+ candles (meaning the period should always be >100 ?) Is this documented anywhere? I've been trying to get a fix for this issue for a very long time now. Please see if you can provide any input on this: https://github.com/anandanand84/technicalindicators/issues/216#issuecomment-864588738

marcusmota commented 2 years ago

This isn't documented, this is just how I "fixed" the issue :P the value does not need to be 100, try to add more candles until you start to have the same value of tv.