Indicators/probuilder · probacktest · proorder · proscreener

MACDLine

MACDLine in ProBuilder returns the raw MACD line, the short EMA minus the long EMA of price, distinct from the MACD histogram. Syntax, formula, examples.

Syntax

probuilder
MACDLine[S,L,Si](price)

Parameters

NameTypeDefaultDescription
Sinteger12Period of the short exponential average.
Linteger26Period of the long exponential average.
Siinteger9Signal period. Required by the shared MACD signature but has no effect on the value of the line itself.
priceprice sourcecloseSeries both averages are computed on, usually close.

Formula

code
MACDLine = ExponentialAverage[S](price) - ExponentialAverage[L](price)

The three MACD functions fit together as:

code
MACDsignal = ExponentialAverage[Si](MACDLine)
MACD       = MACDLine - MACDsignal        // the histogram

How it works

The MACD line measures the spread between a fast and a slow exponential average. When the short average pulls away above the long one, the line rises above zero, reflecting accelerating upside momentum; when the short average falls below, the line goes negative. Because both inputs are averages of the same series, the line oscillates around zero without being bounded.

The naming across the three related functions is the usual source of confusion, and it differs from some other platforms. In ProBuilder, MACD[S,L,Si](price) returns the histogram, that is the line minus its signal. MACDLine returns the raw line described on this page. MACDsignal returns the Si-period exponential average of the line. Any strategy ported from an environment where MACD() denotes the raw line must be rewritten to call MACDLine instead.

One practical consequence: since the histogram equals MACDLine - MACDsignal, the histogram is positive exactly when the line is above its signal, and a histogram zero-cross is the same event as a line and signal crossover.

Examples

Example 1, Histogram versus line comparison (Indicator)

probuilder
// MACD[...] returns the histogram (line minus signal)
i1 = MACD[12,26,9](close)
// MACDLine returns the raw line (12 EMA minus 26 EMA)
i2 = MACDLine[12,26,9](close)
IF i1 < i2 AND i1[1] > i2[1] THEN
  bullishSignal = 1
  bearishSignal = 0
ELSIF i1 > i2 AND i1[1] < i2[1] THEN
  bullishSignal = 0
  bearishSignal = -1
ELSE
  bullishSignal = 0
  bearishSignal = 0
ENDIF
RETURN bullishSignal, bearishSignal

Compares the histogram with the line. Since the histogram equals line minus signal, the histogram sits below the line exactly when the signal line is positive, so these crossings mark the signal line moving through zero.

Example 2, Line and signal crossover entry (ProOrder)

probuilder
// Long on a MACD line cross above the signal while still below zero
line   = MACDLine[12,26,9](close)
signal = MACDsignal[12,26,9](close)

IF NOT LongOnMarket AND line CROSSES OVER signal AND line < 0 THEN
  BUY 1 CONTRACT AT MARKET
ELSIF LongOnMarket AND line CROSSES UNDER signal THEN
  SELL AT MARKET
ENDIF

Enters on the classic crossover, restricted to crossovers that occur below the zero line, and exits on the opposite cross.

Example 3, Zero-line cross scan (ProScreener)

probuilder
// Instruments whose MACD line just turned positive
line = MACDLine[12,26,9](close)
SCREENER[line CROSSES OVER 0](line AS "MACD line")

Returns instruments where the 12-26 exponential average spread crossed above zero on the current bar, a momentum regime change.

Interpretation

A positive line means the short average is above the long one, the standard definition of upside momentum; a negative line means the reverse. The zero cross therefore marks a momentum regime change and is roughly equivalent to a fast and slow average crossover on the price chart.

Crossovers between the line and MACDsignal are the classic trade trigger, faster than the zero cross but noisier. Divergences, where price sets a new extreme that the line does not confirm, are the third common reading; DivergenceMACD automates their detection.

Common errors and gotchas

  • MACD is not the line. In ProBuilder, MACD[12,26,9](close) returns the histogram. Code translated from platforms where the MACD function returns the raw line will produce different signals unless it is changed to MACDLine.
  • The Si parameter is inert here. MACDLine[12,26,9](close) and MACDLine[12,26,2](close) return identical values. The signal period exists in the brackets only so the three MACD functions share one signature.
  • Values scale with price. The line is an absolute price difference, so readings are not comparable across instruments or after large price changes. For cross-instrument scans, normalise, for example by dividing by close.
  • Short minus long, in that order. The first period must be the smaller one. Swapping them, as in MACDLine[26,12,9](close), flips the sign of the output and inverts every signal.
  • MACD, the histogram, line minus signal.
  • MACDsignal, exponential average of the line, the crossover trigger.
  • DivergenceMACD, built-in divergence detection on MACD.
  • ExponentialAverage, the smoothing both components are built from.
  • PriceOscillator, percentage-based variant of the same spread idea.
  • Momentum, raw price difference over N bars.
  • ROC, rate of change, momentum as a percentage.
  • Average, simple moving average for comparison.