【问题标题】:issue on pandas_ta adx indicatorissue on pandas_ta adx indicator
【发布时间】:2022-11-09 11:28:41
【问题描述】:

when i run this code it's obvious get this error s missing close value.

df['ADX'] = ta.adx(df['High'], df['Low'],length = 14)
df

output:

TypeError                                 Traceback (most recent call last)
<ipython-input-23-1031ca130ef0> in <module>
----> 1 df['ADX'] = ta.adx(df['High'], df['Low'],length = 14)
      2 df

TypeError: adx() missing 1 required positional argument: 'close'

now when give closing value and run

df['ADX'] = ta.adx(df['High'], df['Low'],df['Close'],length = 14)
df

output:



`enter code here`ValueError: Wrong number of items passed 3, placement implies 1

if any one know where i am doing wrong please let me know .

this is how i am gettinf dataframe

df = get_history(symbol = "BTCUSDT", interval = "1d", start = timestamp)
df   
  • What is ta? how do I import?
  • @scott Boston usually imported like - import pandas_ta as ta

标签: python pandas dataframe


【解决方案1】:

The ADX indicator generates three dataframe columns, which is why there is this exception. Do this like this:

a = ta.adx(df['High'], df['Low'], df['Close'], length = 14)
df = df.join(a)
df

you will get three columns with data

(ADX_14 DMP_14 DMN_14)

and you can remove unnecessary columns with the drop function

  • What is the difference here to what the other answer suggests?
  • I have been working on this for two days! Thank you for finally solving my issue.
【解决方案2】:

Try this:

import talib

real = talib.ADX(df['High'], df['Low'], df['Close'], timeperiod=14)
print(real)

What library do you use to calculate the indicator?

If it doesn't work out, show how you get the data and from where on "BTCUSDT"?

  • as wrought in heading it's pandas_ta library . import pandas_ta as ta also one thing more when i run other indiactors like : ema and rsi it works but don't know what wrong with adx df["EMA"] = ta.ema(df.Close, length = 5, offset=None, append=True) df df["RSI"] = ta.rsi(df['Close'], length = 14 ,offset=None, append=True ) df
  • Most likely you have something wrong with the 'BTCUSDT' data. I tried it like this:adx = ta.adx(df['H'], df['L'], df['C'], length = 14). You will have your own data with other column names not H, L, C. The indicator was calculated without any problems.
  • this is how i import data not able to send code at ones so break kindly join them def get_history(symbol, interval, start, end = None): bars = client.get_historical_klines(symbol = symbol, interval = interval, start_str = start, end_str = end, limit = 1000) df = pd.DataFrame(bars) df["Date"] = pd.to_datetime(df.iloc[:,0], unit = "ms")
  • df.columns = ["Open Time", "Open", "High", "Low", "Close", "Volume", "Clos Time", "Quote Asset Volume", "Number of Trades", "Taker Buy Base Asset Volume", "Taker Buy Quote Asset Volume", "Ignore", "Date"] df = df[["Date", "Open", "High", "Low", "Close", "Volume"]].copy() df.set_index("Date", inplace = True) for column in df.columns: df[column] = pd.to_numeric(df[column], errors = "coerce") return df
  • For verification, request data from yaho: import pandas_datareader.data as web df = web.DataReader('^GSPC', 'yahoo', start='2010-05-15', end='2021-10-01')
【解决方案3】:
df['ADX'] = ta.adx(df['High'], df['Low'],length = 14)['ADX_14']
you can run "print(ta.adx(df['High'], df['Low'],length = 14))"
    猜你喜欢
    • 2021-01-06
    • 2022-12-28
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 2022-12-01
    • 2021-02-27
    • 2019-05-12
    • 2018-01-20
    相关资源
    最近更新 更多