Skip to content

Commit 76246d5

Browse files
Update Indicator_MACD_Histogram_Gradient.ipynb
Formula For MACD Indicator Calculation
1 parent 5582a4b commit 76246d5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

examples/Indicator_MACD_Histogram_Gradient.ipynb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,24 @@
2121
"source": [
2222
"infile = 'data/t_data.csv'\n",
2323
"\n",
24-
"df = pd.read_csv(infile, index_col=0, parse_dates=True)"
24+
"#Data Used In This Example\n",
25+
"df = pd.read_csv(infile, index_col=0, parse_dates=True)",
26+
"#Formula Used For Calculation\n",
27+
"# Get the 26-day EMA of the closing price\n",
28+
"#k = df['Close'].ewm(span=12, adjust=False, min_periods=12).mean()\n",
29+
"# Get the 12-day EMA of the closing price\n",
30+
"#d = df['Close'].ewm(span=26, adjust=False, min_periods=26).mean()\n",
31+
"# Subtract the 26-day EMA from the 12-Day EMA to get the MACD\n",
32+
"#macd = k - d\n",
33+
"# Get the 9-Day EMA of the MACD for the Trigger line\n",
34+
"#macd_s = macd.ewm(span=9, adjust=False, min_periods=9).mean()\n",
35+
"# Calculate the difference between the MACD - Trigger for the Convergence/Divergence value\n",
36+
"#macd_h = macd - macd_s\n",
37+
"# Add all of our new values for the MACD to the dataframe\n",
38+
"#df['MACD_12_26_9'] = df.index.map(macd)\n",
39+
"#df['MACDh_12_26_9'] = df.index.map(macd_h)\n",
40+
"#df['MACDs_12_26_9'] = df.index.map(macd_s)\n"
41+
2542
]
2643
},
2744
{

0 commit comments

Comments
 (0)