I have the following code:
import MetaTrader5 as mt5
import pandas as pd
import time
import pandas_ta as ta
import mplfinance as mpf
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1500)
if not mt5.initialize():
print("initialize failed")
mt5.shutdown()
account="FOO"
authorized=mt5.login(account, server="FOO")
if authorized:
print("Authorized")
else:
print("failed to connect at account #{}, error code: {}".format(account, mt5.last_error()))
cndl_72 = mt5.copy_rates_from_pos("BTCUSD", mt5.TIMEFRAME_M1, 1, 72)
cndl_72_df = pd.DataFrame(cndl_72)
cndl_72_df['time']=pd.to_datetime(cndl_72_df['time'], unit='s')
cndl_72_df.rename(columns={'time': 'date', 'tick_volume' : 'volume'}, inplace=True)
cndl_72_df.set_index('date', inplace=True)
cndl_72_df.drop(['spread','real_volume'], axis=1, inplace=True)
mpf.plot(cndl_72_df, type='candle')
The objective is to get an MACD indicator to appear.
EDIT #1: see attempt #1 in comments. changes throw a key error.
EDIT #2: see changes https://pastebin.com/qAiu1PkS, which throws a new error:
EDIT #3: type error fixed, now I can successfully calculate MACD from my dataframe and append it if necessary. Now I need to figure out charting...
EDIT #4: charting done, see comments. The MACD plot looks similar so the data could be accurate. Just need to make it prettier...
Authorized
Traceback (most recent call last):
File "C:\Users\hello\Documents\projects\alerter_venv\main.py", line 38, in <module>
mpf.plot(cndl_72_df, type='candle', addplot=plots)
File "C:\Users\hello\Documents\projects\alerter_venv\lib\site-packages\mplfinance\plotting.py", line 707, in plot
ax = _addplot_columns(panid,panels,ydata,apdict,xdates,config)
File "C:\Users\hello\Documents\projects\alerter_venv\lib\site-packages\mplfinance\plotting.py", line 997, in _addplot_columns
yd = [y for y in ydata if not math.isnan(y)]
File "C:\Users\hello\Documents\projects\alerter_venv\lib\site-packages\mplfinance\plotting.py", line 997, in <listcomp>
yd = [y for y in ydata if not math.isnan(y)]
TypeError: must be real number, not str
As far as I can tell there aren't any strings that could be producing this. How do I find the source?