# Not getting MACD(12, 26, 9) correctly

def get_signal_bars_test(symbols, rate, slow=26, fast=12):
endt = pd.Timestamp(current - datetime.timedelta(days=1), tz=‘America/New_York’).isoformat()
stdt = pd.Timestamp(current - datetime.timedelta(days=50), tz=‘America/New_York’).isoformat()
# Get last 500 day closing price
data1 = api.get_barset(symbols, ‘1D’, limit=500, start=stdt, end=endt).df
# Current day live price
data2 = api.get_barset(symbols, rate, limit=1).df
print(data2)
# Append last 500 closing price with live price
data = data1.append(data2)
for x in symbols:
data.loc[:, (x, ‘fast_ema’)] = ema(data[x][‘close’], fast)
data.loc[:, (x, ‘slow_ema’)] = ema(data[x][‘close’], slow)
print ( str(x) + " fast at " + str(data[x].iloc[-1][‘fast_ema’]) + " " + str(datetime.datetime.now().strftime("%x %X")))
print ( str(x) + " slow at " + str(data[x].iloc[-1][‘slow_ema’]) + " " + str(datetime.datetime.now().strftime("%x %X")))
# Calculate MACD(12,26)
data.loc[:, (x, ‘macd’ )] = data[x][‘fast_ema’]-data[x][‘slow_ema’]

``````    #Calculate Signal (MACD, 9)
data.loc[:, (x, 'signal_ema' )] = ema(data[x]['macd'], 9)
print ( str(x) + " macd  at " + str(data[x].iloc[-1]['macd']) + " " + str(datetime.datetime.now().strftime("%x %X")))
print ( str(x) + " signal_ema  at " + str(data[x].iloc[-1]['signal_ema']) + " " + str(datetime.datetime.now().strftime("%x %X")))
return data
``````

df1=get_signal_bars_test([‘AMC’, ‘MN’], ‘1Min’, 26, 12)

# print(df1)

df1.to_csv(‘A.csv’, index=True)

output:
AMC fast at nan 08/17/20 12:23:50
AMC slow at nan 08/17/20 12:23:50
MN fast at nan 08/17/20 12:23:50
MN slow at nan 08/17/20 12:23:50
AMC macd at nan 08/17/20 12:23:50
AMC signal_ema at nan 08/17/20 12:23:50