Skip to content

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 ​

InputTypeDefault
Fast lengthint12
Slow lengthint26
Sourcesource"close"
Signal smoothingint9
Histogram abovecolor"#26A69A"
Histogram belowcolor"#FF5252"
MACD colorcolor"#2962FF"
Signal colorcolor"#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" });

AlphaScript language v0.1 · runtime 0.2.0