I'm trying to call TA-lib's ADX function, which according to its documentation, has the following parameters:
ADX(high, low, close[, timeperiod=?])
Average Directional Movement Index (Momentum Indicators)
Inputs:
prices: ['high', 'low', 'close']
Parameters:
timeperiod: 14
Outputs:
real
I am calling it like so:
from talib import abstract
params = {'timeperiod': 14}
indicator_fn = abstract.Function('ADX')
val = indicator_fn(0.5, 0.2, 0.3, **params)
print(val)
But it fails with:
Traceback (most recent call last):
File "/home/stark/Work/test/test.py", line 11, in <module>
val = indicator_fn(0.5, 0.2, 0.3, **params)
File "talib/_abstract.pxi", line 398, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 277, in talib._ta_lib.Function.set_function_args
File "talib/_abstract.pxi", line 462, in talib._ta_lib.Function.__check_opt_input_value
TypeError: Invalid parameter value for timeperiod (expected int, got float)
It doesn't seem to make sense to me. timeperiod
is clearly an int
, no?
If I attempt to call it like so:
val = indicator_fn([0.5, 0.2, 0.3], timeperiod=14)
it fails with TypeError: Invalid parameter value for timeperiod (expected int, got list)
If I try
val = indicator_fn(prices=[0.5, 0.2, 0.3], timeperiod=14)
it fails with KeyError: 0.5
If I try:
val = indicator_fn(prices={'high': 0.5, 'low': 0.2, 'close': 0.3}, timeperiod=14)
it fails with TypeError: unhashable type: 'dict'
Any insights here are greatly appreciated!
The 3 first args have to be arrays, e.g:
val = indicator_fn(np.asarray([0.5]), np.asarray([0.2]), np.asarray([0.3]), timeperiod=14)
According to the tests, indicator_fn = abstract.Function('ADX', timeperiod=14)
might solve the issue as well.
The error message you're getting is indeed very misleading, you might want to report that to the dev.