I was trying to get the ATR for a couple of symbols (BTCUSDT, ETHUSDT) with TA-Lib but the results would be all "nan", and I can't figure out why.
Here is an minimal example with exemplary data:
import talib
import numpy
highs = numpy.array([10697.12, 10706.16, 10744.75, 10747.88, 10745.42])
lows = numpy.array([10683.51, 10694.72, 10705.16, 10728.22, 10727.29])
closes = numpy.array([10696.47, 10705.16, 10728.23, 10742.46, 10730.27])
print(talib.ATR(highs, lows, closes, timeperiod = 5))
And the output:
[nan nan nan nan nan nan nan nan nan nan nan nan nan nan]
Your example is supposed to result in something like
and if you try
timeperiod = 3
you'll get something likeBecause ATR is a rolling function with timeperiod = N. According to the readme of TA-Lib python wrapper
Technically count of
NaN
s (lookback period) depends on optional arguments you pass to rolling mean indicator (or default values used in it). But it may be not equal to it. For ex., in case of rolling means of rolling means indicator. If you don't want to just skipNaN
's from the beginning of a result array but know exact number of data to skip then you may get this value. I suppose in python this could be achieved via Ta-Lib's Abstract API and lookback property of a function object.