I am trying to calculate Bollinger Bands using Pandas_TA
(i) Data obtained from yfinance
import yfinance as yf
import numpy as np
from ta.volatility import BollingerBands
AMBEV = yf.download('ABEV3.SA', start = '2020-01-01', interval = '1d')
indicator_bb = BollingerBands(AMBEV['Adj Close'], window=20, window_dev=2)
AMBEV['bb_bbm'] = indicator_bb.bollinger_mavg()
BBH = indicator_bb.bollinger_hband()[-1]
AMBEV['bb_bbl'] = indicator_bb.bollinger_lband()
(ii) Data obtained from Binance API
if __name__ == '__main__':
client = Client(config.API_KEY, config.API_SECRET)
klines = client.get_historical_klines(TRADE_SYMBOL, TIME_INTERVAL, "1 day ago UTC", limit=30)
for candles in range(len(klines)-1):
closes.append(float(klines[candles][4]))
closes = pd.DataFrame(closes, column='Close')
if len(closes) > 21:
bb = BollingerBands(closes, window=20, window_dev=2)
closes['bb_h'] = bb.bollinger_hband()
closes['bb_l'] = bb.bollinger_lband()
What's the issue? When using data from yfinance it works normally, but when using the binance API data it fails and shows the following error:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
I don't understand the nature of this error as i am not comparing a dataframe with anything at all, i was expecting to have this error when for example building an if statement and using dataframe as a statement to be compared.
Anyway, do you have any ideas what could be going wrong here?