MACD implementation in python

Jayasuryan0821
Hello everyone,
I'm new to trading, I implemented the macd technical indicator . The data i computed does not correspond to the data from Zerodha is there any change to my function I can make or do I have to add any parameters in the .ewm method. Please let me know how I can address this problem.

. Here is the code below

'''
def MACD(DF,a,b,c):
"""function to calculate MACD
typical values a(fast moving average) = 12;
b(slow moving average) =26;
c(signal line ma window) =9"""
df = DF.copy()
df["MA_Fast"]=df["close"].ewm(span=a,min_periods=a).mean()
df["MA_Slow"]=df["close"].ewm(span=b,min_periods=b).mean()
df["MACD"]=df["MA_Fast"]-df["MA_Slow"]
df["Signal"]=df["MACD"].ewm(span=c,min_periods=c).mean()
df.dropna(inplace=True)
return df
'''
macf.png 228.3K
Sign In or Register to comment.