ta-lib-python icon indicating copy to clipboard operation
ta-lib-python copied to clipboard

Semantics of slowk_matype and slowd_matype are unclear

Open metaperl opened this issue 9 years ago • 9 comments

The docs for STOCH() do not document slowk_matype or slowd_matype. The official docs on this function do not mention these arguments at all.

metaperl avatar Mar 30 '15 21:03 metaperl

Something like this should work:

from talib import MA_Type

slowk, slowd = STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=MA_Type.SMA, slowd_period=3, slowd_matype=MA_Type.EMA)

All of the available types are listed here and should work for any function that allows controlling the type of moving average used to generate its output.

briancappello avatar Mar 30 '15 21:03 briancappello

Thank you for your rapid response. However you do see the documentation issue don't you? The STOCH() docs refer to you tadoc.com, and they have no information on the correct calling conventions. And there is nothing is the python talib docs which says what you are saying.

So anyone looking at the docs stands to be confused by the magic numbers in the example. Interestingly, your example uses 2 different moving averages but the example uses the magic number of zero for both.

On Mon, Mar 30, 2015 at 2:16 PM, Brian Cappello [email protected] wrote:

Something like this should work:

from talib import MA_Type

slowk, slowd = STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=MA_Type.SMA, slowd_period=3, slowd_matype=MA_Type.EMA)

All of the available types are listed here https://github.com/mrjbq7/ta-lib/blob/master/talib/common.pyx#L51 and should work for any function that allows controlling the type of moving average used to generate its output.

— Reply to this email directly or view it on GitHub https://github.com/mrjbq7/ta-lib/issues/77#issuecomment-87833787.

Terrence Brannon 818-359-0893 (cell)

metaperl avatar Mar 30 '15 21:03 metaperl

@metaperl Yes, you are right, it could be more clear! That's very likely my fault; and probably attributable to "the curse of knowledge" - so thank you for the heads up :) In the meantime, anywhere a function takes a moving average type as a parameter, any of the MA_Type constants / magic numbers (0-8) should work. (The underlying C-level functions are type-hinted on TA_MAType, as opposed to any of the specific TA_MAType_XXX types. So either upstream's code is broken, or any of the types should work!)

briancappello avatar Mar 30 '15 22:03 briancappello

The C library uses integer constants (and the python library as well, but with handy MAType.SMA aliases), but perhaps it would be nicer if we used coercion, something like this:

>>> class MAType(object):
...     def __init__(self, n):
...         self.n = n
...     def __int__(self):
...         return self.n
... 
>>> SMA = MAType(0)
>>> int(SMA)
0

mrjbq7 avatar Apr 01 '15 16:04 mrjbq7

Do you know how these compare to tradingview stochastic indicator? They only have 3 input fields. Length , SmoothK and SmoothD

I am using TALIB = 14,3,0,3,0 and TradingView 14,3,3 The same periods give me different results. Tradingview = K/D 46.793 / 33.0618 Script = K/D 24.8443 / 18.9583

snub-fighter avatar Dec 14 '18 04:12 snub-fighter

Same Issue Here Some one please help

RaninsVand avatar Dec 19 '19 23:12 RaninsVand

Do you know how these compare to tradingview stochastic indicator? They only have 3 input fields. Length , SmoothK and SmoothD

I am using TALIB = 14,3,0,3,0 and TradingView 14,3,3 The same periods give me different results. Tradingview = K/D 46.793 / 33.0618 Script = K/D 24.8443 / 18.9583

Similar Problem Help Please

gavishpoddar avatar Dec 19 '19 23:12 gavishpoddar

I mean, you could always look at the code and it should be pretty obvious:

https://github.com/TA-Lib/ta-lib/blob/master/src/ta_func/ta_STOCH.c#L502

mrjbq7 avatar Dec 19 '19 23:12 mrjbq7

@RaninsVand, @gavishpoddar, @snub-fighter I was also facing the issue; solved it by computing the STOCH from its formula, see https://gist.github.com/mouchh/0e4e83443d43f3d68cfe220ccac3f36a

@mrjbq7 I wish I could understand the talib code but have to admit it is a bit too high level 😄

mouchh avatar Nov 29 '20 16:11 mouchh