Menu

#107 CCI should use

open
nobody
None
5
2020-12-09
2020-12-09
No

There is a bug in CCI - for some data it returns wrong results. For ex.:

import talib
import numpy as np

timeperiod = 8
data = [1.1] *timeperiod

lows = np.asarray(data)
highs = lows.copy()
closes = lows.copy()

talib_ret = talib.CCI(highs, lows, closes, timeperiod=timeperiod)
print("talib", talib_ret[-1])
>>>> talib 66.66666666666667

while 0.0 is expected at talib_ret[-1].

That's because TA_CCI() contains:

      if( (tempReal != 0.0) && (tempReal2 != 0.0) )
      {
         outReal[outIdx++] = tempReal/(0.015*(tempReal2/optInTimePeriod));
      }
      else
         outReal[outIdx++] = 0.0;

while it should be:

      if( (!TA_IS_ZERO(tempReal)) && (!TA_IS_ZERO(tempReal2)) )
      {
         outReal[outIdx++] = tempReal/(0.015*(tempReal2/optInTimePeriod));
      }
      else
         outReal[outIdx++] = 0.0;

where TA_IS_ZERO() compares absolute argument value with 1e-14 instead of 0.0.
Otherwise TA_CCI() will return:

>>> 2.220446049250313e-16 / (0.015*(1.5543122344752192e-15 / 7))
66.66666666666667

Related discussion is here

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.