Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Srsi wrong values #694

Closed
matz9x opened this issue Nov 9, 2017 · 5 comments
Closed

Srsi wrong values #694

matz9x opened this issue Nov 9, 2017 · 5 comments
Labels

Comments

@matz9x
Copy link

matz9x commented Nov 9, 2017

Srsi indicator gives, to me, wrong results, with oscillations greater than the maximum srsi range (typically 0-100% or 0-1). If this issue is confirmed the validity of both macd-srsi and cci-srsi strategies is compromised. I think that is needed a fix on the srsi.js file inside lib folder. Unfortunately I'm not an expert in javascript language and I can give support only on the technical analysis part.
Further information on srsi: https://www.tradingview.com/wiki/Stochastic_RSI_(STOCH_RSI)

The cyan column gives the value of srsi
2017-11-09

Thank you for the support

@matz9x
Copy link
Author

matz9x commented Nov 18, 2017

Someone else noticed this issue?

@Lucidarme
Copy link

This issue come from the lib/srsi.js file. In this file, there is theses lines:

var highestRSI = Math.max(...RSI)
var lowestRSI = Math.min(...RSI)
var stochK = 0
stochK = ((s.period.rsi - lowestRSI) / (highestRSI - lowestRSI)) * 100

So it seems to be right. But sometime, s.period.rsi is lower than lowestRSI ... And it gives negatives values! And sometime s.period.rsi is higher than highestRSI... And it gives values higher than 100.

So now the question is:
What we should set to stochK when s.period.rsi is lower than lowestRSI or higher than highestRSI??

@matz9x
Copy link
Author

matz9x commented Nov 23, 2017

Thank you for your analysis! However, I think that this is not the real issue because the lowest RSI is computed among a set of values, including the actual RSI value. It means that, in a worst case scenario s.period.rsi - lowestRSI is equal to zero.
e.g.1
RSI = [10 15 40 80 65 20 5]
For this set of data the lowest RSI is 5 it means that:
stochk = (5 - 5) / (80 - 5) > 0
e.g.2
even if there is 0 on the last position stochk is still equal to 0
RSI = [0 15 40 80 65 20 0]
stochk = (0 - 0)/(80 - 0) = 0
So the equation is well implemented but the computation is wrong and I don't know what's the reason, mainly because I don't understand JS language.

My suspects however are focused on this part of the code:

    if (typeof s.period.rsi !== 'undefined')
      s.lookback.slice(0, k).forEach(function (period) {
        if (period.rsi)
          RSI.push(period.rsi)
      })

I would appreciate your feedback on his purpose inside the code, in particular RSI.push(period.rsi)

@Lucidarme
Copy link

That is the problem, in this code, current RSI is not push. I added

RSI.push(s.period.rsi)

just after the lines you wrote, and now I have reals values. However, these value are not the same that tradingview.com SRSI indicator...

If you want some explaination about the code you wrote:

s.lookback.slice(0, k).forEach(function (period) {}

this line will separate all periods between the current period-1 and the current period-k-1, and each period will be accessible via "period". It's like a "for" in some ways.

and then,

RSI.push(period.rsi)

is used to push each rsi of each period inside RSI array.

@aquamanjl
Copy link
Contributor

This should now be fixed by #1196

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants