Appearance
MACD
EMA difference, signal line and histogram.
Kind indicator · Drawn in its own pane
Try it
On the chart, press / and choose MACD under Oscillators. To change it, copy the source below into the AlphaScript editor.
Inputs
| Input | Type | Default |
|---|---|---|
| Fast length | int | 12 |
| Slow length | int | 26 |
| Source | source | "close" |
| Signal smoothing | int | 9 |
| Histogram above | color | "#26A69A" |
| Histogram below | color | "#FF5252" |
| MACD color | color | "#2962FF" |
| Signal color | color | "#FF6D00" |
Source
From packages/alphascript/indicators/macd.as.js.
js
indicator({ name: "MACD", shortTitle: "MACD", overlay: false });
const fast = input.int("Fast length", 12, { min: 1 }), slow = input.int("Slow length", 26, { min: 1 });
const src = input.source("Source", "close");
const signal = input.int("Signal smoothing", 9, { min: 1, max: 50 });
const m = ta.macd(src, fast, slow, signal);
plot(m.hist, { title: "Histogram", style: "columns", colorUp: input.color("Histogram above", "#26A69A", { group: "Style" }), colorDown: input.color("Histogram below", "#FF5252", { group: "Style" }) });
plot(m.macd, { title: "MACD", color: input.color("MACD color", "#2962FF", { group: "Style" }) });
plot(m.signal, { title: "Signal", color: input.color("Signal color", "#FF6D00", { group: "Style" }) });
hline(0, { title: "Zero", color: "rgba(120,123,134,0.5)", style: "dashed" });