Skip to content
All library documents

Passing Pandas Price Series to TA-Lib for ATR Calculation

Article Quant Q&A · Author: user2300940

Summary

The document answers a practical question about calculating a 20-period Average True Range from a pandas DataFrame. The reported issue arises because TA-Lib expects array-like numerical inputs rather than pandas Series in this usage. Converting the High, Low, and Close columns to their underlying values before calling the ATR function resolves the input mismatch.

The answer is narrowly focused on data compatibility. It does not explain ATR's formula, interpret the indicator, or discuss alternative implementations, and it provides no example output or validation beyond the suggested adjustment. Users may need to confirm that their columns contain suitable numeric data and that their TA-Lib setup accepts the resulting arrays.

Key ideas

  • TA-Lib ATR can be calculated from the High, Low, and Close price columns.
  • Pass the columns' underlying array values when pandas Series inputs cause an error.
  • Set the ATR lookback period to 20 for the requested calculation.
  • This answer addresses input format rather than ATR interpretation or validation.

Tags

Full text
# talib.ATR or other ATR calculation


# talib.ATR or other ATR calculation












I have my data stored in `df1` with the columns: `Date Time Open High Low Close Vol OI` I want to calculate the 20 period ATR from my df1. Using TA-Lib I have tried the following which gives an error:

```
todayATR = talib.ATR(df1['High'],df1['Low'],df1['Close'],timeperiod=20)
```

I am new to python so I might have missed something simple.

## Answer by Helin (score 1)

https://quant.stackexchange.com/a/37405

`talib` functions do not accept `pandas` time series as inputs. Try

```
talib.ATR(df1['High'].values, df1['Low'].values, df1['Close'].values, timeperiod=20)
```

instead.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.