Back to Community
ATR values turning Nan after some values

Any specific reason why talib.ATR turns to print NaN after some calculations

Loading notebook preview...
2 responses

Talib is really bad at dealing with nan-values and there are a few points in the data frame which contain nans:

    high    low     close_price  
2015-05-01 14:50:00+00:00   NaN     NaN     NaN  
2015-05-01 16:00:00+00:00   NaN     NaN     NaN  
2015-05-01 16:40:00+00:00   NaN     NaN     NaN  
2015-05-01 16:58:00+00:00   NaN     NaN     NaN  
2015-05-01 18:57:00+00:00   NaN     NaN     NaN  

As soon as the first nan occours, Talib's ATR starts spitting out nans for the rest of the calculation. You could work around it by replacing the nans with the last valid value:

m15 = m15.fillna(method='ffill')  

Of couse this workaround might not be appropriate for other cases. If your data frame contains mostly nans, the results wouldn't have any meaning and it might be better to skip this day / symbol all together. It also depends on what you are trying to do with the results...

Thank you Tentor,
I am trying to build an ATR trailing stop strategy, will try to fill the NaN's with the previous candle details and see.