Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about RSI #16

Closed
ydcool opened this issue Mar 22, 2020 · 3 comments
Closed

Confused about RSI #16

ydcool opened this issue Mar 22, 2020 · 3 comments

Comments

@ydcool
Copy link

ydcool commented Mar 22, 2020

go-talib/talib.go

Lines 2819 to 2840 in cd53a92

today := 0
prevValue := inReal[today]
prevGain := 0.0
prevLoss := 0.0
today++
for i := inTimePeriod; i > 0; i-- {
tempValue1 = inReal[today]
today++
tempValue2 = tempValue1 - prevValue
prevValue = tempValue1
if tempValue2 < 0 {
prevLoss -= tempValue2
} else {
prevGain += tempValue2
}
}
prevLoss /= float64(inTimePeriod)
prevGain /= float64(inTimePeriod)
if today > 0 {

Hi Mark, just start reading this source codes, and got a little confused about the today variable in func Rsi, it seems that at L2840 the today will be 3 at least because there's an auto-increament operation at L2823 and min value of inTimePeriod is 2, so the else part at L2850 would never be reached. Is that right?

@ydcool
Copy link
Author

ydcool commented Mar 22, 2020

I also read the RSI in c at https://sourceforge.net/p/ta-lib/code/HEAD/tree/trunk/ta-lib/c/src/ta_func/ta_RSI.c#l358
I'm not quite familar with c , just wonder that could the startIdx be simplified as 0?

@markcheno
Copy link
Owner

Hi Dominic,
This code is a straight up port from the Java version of TA-Lib. So any peculiarities like that exist in the original version as well. Since I test the output of this version against the original TA-Lib, I'm inclined to leave it alone for now.

@ydcool
Copy link
Author

ydcool commented Mar 23, 2020

I see. I have read the java version and finally figured it out. The reason that your code got the correct result is the last for loop coverd the caculations, and those dead codes above have no side effects.

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

No branches or pull requests

2 participants