ta icon indicating copy to clipboard operation
ta copied to clipboard

Getting warnings @ ADX indicator

Open CrossfireX opened this issue 4 years ago • 7 comments

Running the "visualize_features.ipynb" example gets me this warning: /home/vant/projects/python/ta/env-ta/lib/python3.7/site-packages/ta/trend.py:468: RuntimeWarning: invalid value encountered in double_scalars dip[i] = 100 * (self._dip[i]/self._trs[i]) /home/vant/projects/python/ta/env-ta/lib/python3.7/site-packages/ta/trend.py:472: RuntimeWarning: invalid value encountered in double_scalars din[i] = 100 * (self._din[i]/self._trs[i]) Looks like an error at ADX trend indicator. Can you please take a look at it? Thanks and keep up the good work!

CrossfireX avatar Nov 15 '19 21:11 CrossfireX

Hi @CrossfireX ,

This is a warning, not an error. You can use ADX and the results will be right.

Anyway, I will try to solve!

Thank you.

bukosabino avatar Nov 16 '19 01:11 bukosabino

True, the D+ and D- worked correctly, now the trend adx is working too.

CrossfireX avatar Nov 16 '19 08:11 CrossfireX

same issue with ADX

alm0ra avatar Mar 22 '20 18:03 alm0ra

that's really annoying. Has anybody found a workaround to eliminate that while debugging in vscode?

alexk380 avatar Mar 12 '21 17:03 alexk380

Hi all,

Due to some reason _trs series is longer by 1 count. We can make the following edit in '/lib/site-packages/ta/trend.py'

line # 760 - 788

`def adx(self) -> pd.Series:
        dip = np.zeros(len(self._trs)-1)
        for i in range(len(self._trs)-1):
            dip[i] = 100 * (self._dip[i] / self._trs[i])

        din = np.zeros(len(self._trs)-1)
        for i in range(len(self._trs)-1):
            din[i] = 100 * (self._din[i] / self._trs[i])

        directional_index = 100 * np.abs((dip - din) / (dip + din))

        adx_series = np.zeros(len(self._trs))
        adx_series[self._window] = directional_index[0 : self._window].mean()

        for i in range(self._window + 1, len(adx_series)):
            adx_series[i] = (
                (adx_series[i - 1] * (self._window - 1)) + directional_index[i - 1]
            ) / float(self._window)

        adx_series = np.concatenate((self._trs_initial, adx_series), axis=0)
        adx_series = pd.Series(data=adx_series, index=self._close.index)

        adx_series = self._check_fillna(adx_series, value=20)
        return pd.Series(adx_series, name="adx")`

I've simply reduced the series dip and din by 1, and running the loop also -1 times.

informankur avatar May 26 '21 15:05 informankur

Informankur's fix solved it for me. I still get the same adx output. Warning is gone :D

4rumprom avatar May 30 '21 00:05 4rumprom

same error for me

arturdaraujo avatar Oct 17 '22 18:10 arturdaraujo