Skip to content

The gap between a fast and a slow moving average, in pips.

MACD is the fast EMA minus the slow EMA. It is positive when the recent price is above the longer average and grows as the trend speeds up. With signalEMAPeriods, it adds an EMA of MACD as a signal line and the difference between the two as a histogram. Cloud9Trader gives MACD in pips, so it reads the same on every currency pair; most platforms give it in price.

Traders read MACD crossing its signal line as a turn in momentum and MACD crossing zero as the fast average crossing the slow one. A histogram shrinking towards zero shows the move losing pace.

MACD = (EMA(fast) − EMA(slow)) / pip size
signal = EMA(MACD, signalEMAPeriods)
histogram = MACD − signal

Call: macd(fastEMAPeriods, slowEMAPeriods, signalEMAPeriods)

Setting Chart default
fastEMAPeriods: Fast EMA Periods 12
slowEMAPeriods: Slow EMA Periods 26
signalEMAPeriods: Signal EMA Periods 9

What you get: a list of 3, in this order: 1. a number (“MACD”); 2. a number (“MACD Signal”); 3. a number (“MACD Histogram”).

Warm-up: with macd(12, 26, 9), it asks for 26 bars of history and a run-up of 61, and its first value came on bar 35 of the example data.

MACD drawn by its own code on example prices

The prices are made up, hourly, and the same on every page, so the chart shows how the indicator behaves, not how a market behaved.

let wasAbove = false;
function onIntervalClose() {
const lines = macd(12, 26, 9);
const above = lines[0] > lines[1];
if (OPEN_POSITIONS_COUNT === 0 && above && !wasAbove) {
openPosition("BUY", { quantity: 10000, stopLossPips: 25, takeProfitPips: 50 });
}
wasAbove = above;
}

Without signalEMAPeriods, macd(12, 26) gives a single number. On an instrument without pips in the usual sense, such as a crypto pair, the value is scaled by that instrument’s pip size.