The stochastic indicator doesn't work for smooth_k = 1
See original GitHub issueWhich version are you running? The lastest version is on Github. Pip is for major releases. 0.3.2b0
Do you have TA Lib also installed in your environment? Yes
Did you upgrade? Did the upgrade resolve the issue? I upgraded but it didn’t help.
Describe the bug If you try to get the unsmoothed stochastic indicator it throws and exception because the SMA function on TA Lib doesn’t accept the value “1” as the length parameter.
To Reproduce
ta.stoch(df.High, df.Low, df.Close, k=14, smooth_k=1)
Expected behavior The calculation of a Stochastic series getting the same result as TradingView
Screenshots
Additional context
In my installation I changed the line 29 (stoch.py file) from
stoch_k = ma(mamode, stoch.loc[stoch.first_valid_index():,], length=smooth_k)
to
stoch_k = stoch if smooth_k==1 else ma(mamode, stoch.loc[stoch.first_valid_index():,], length=smooth_k)
And apparently it worked:
I also suggested this change but it seems it has been discarded.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
Sorry, I didn’t see it. Yes, it was sufficient. Thanks!
@KimWuWei,
No worries. I’m no Github master either… still learning new things.
Thanks for the quick fix you provided! 😎 Will let you know when it’s available.
KJ