Indicators/probuilder · probacktest · proorder · proscreener

ExponentialAverage

ExponentialAverage in ProBuilder returns the exponential moving average (EMA) of a price or series over N bars. Syntax, formula, examples, and gotchas.

Syntax

probuilder
ExponentialAverage[N](price)

Parameters

NameTypeDefaultDescription
Ninteger20Period of the average. Determines the smoothing factor 2 / (N + 1). Common settings include 9, 12, 21, 26, 50, and 200.
priceprice sourcecloseThe series to smooth. Accepts any price constant or numeric variable, including other indicators.

Formula

code
EMA(t) = alpha * price(t) + (1 - alpha) * EMA(t-1)
where alpha = 2 / (N + 1)

Each new value blends the current price with the previous EMA. The weight of any single bar decays exponentially with age, which is where the name comes from. Unlike a simple average, every past bar retains a small residual influence.

How it works

A simple moving average treats all N bars equally, so an old bar dropping out of the window can move the line as much as a fresh price arriving. The exponential average removes that artifact by weighting bars geometrically: the latest close matters most, the one before it slightly less, and so on. The practical effect is less lag for the same nominal period.

The recursive definition means the calculation depends on prior values. ProRealTime seeds the series from the earliest loaded bar, so the first values after the start of the data are less meaningful. On short data windows, or in ProOrder with a low bar preload, early readings can differ from the same EMA drawn on a longer chart.

ExponentialAverage[N](price) produces the same output as Average[N,1](price); the dedicated function simply makes the intent explicit. Like all ProBuilder averages, it accepts any numeric series, so it is frequently used to smooth oscillators rather than raw price.

Examples

Example 1, Smoothing the RSI (Indicator)

probuilder
// Smooth a 14-period RSI with a 10-period EMA
i1 = RSI[14]
i2 = ExponentialAverage[10](i1)
RETURN i1 as "RSI", i2 coloured(147,112,216) as "smoothed RSI"

Applies a 10-period exponential average to the RSI, plotting both the raw oscillator and its smoothed version in purple. The EMA keeps the smoothed line closer to the raw series than an SMA of the same length would.

Example 2, EMA crossover strategy (ProOrder)

probuilder
// Hold long while the 12-period EMA is above the 26-period EMA
fastEMA = ExponentialAverage[12](close)
slowEMA = ExponentialAverage[26](close)

IF fastEMA CROSSES OVER slowEMA THEN
  BUY 1 CONTRACT AT MARKET
ENDIF
IF fastEMA CROSSES UNDER slowEMA AND LongOnMarket THEN
  SELL AT MARKET
ENDIF

Uses the 12 and 26 periods familiar from the MACD. The reduced lag of exponential averages triggers entries and exits earlier than the equivalent SMA crossover, at the cost of more whipsaws in choppy conditions.

Example 3, Close crossing above the 50 EMA (ProScreener)

probuilder
// List instruments whose close just crossed above the 50-period EMA
ema50 = ExponentialAverage[50](close)
SCREENER[close CROSSES OVER ema50](close AS "Close")

Returns only the instruments where the latest close moved from below to above the 50-period exponential average on the current bar, a momentum-shift scan.

Interpretation

Price versus the EMA. Price sustained above a rising EMA indicates an uptrend on that horizon; price below a falling EMA, a downtrend. Because of its reduced lag, the EMA hugs price more closely than an SMA, so it is often preferred as a trailing trend line on shorter timeframes.

Crossovers. Fast-over-slow EMA crossings signal a momentum shift, the mechanism behind the MACD line. Crossings arrive earlier than with simple averages but also reverse more often; the trade-off is responsiveness against false signals.

Slope. A flattening EMA marks fading momentum before any crossover occurs, and is often the earlier warning.

Common errors and gotchas

  • Wrong bracket type. ExponentialAverage(10, close) raises a syntax error. The period goes in square brackets, the series in parentheses: ExponentialAverage[10](close).
  • History dependence. The recursive formula means the first bars of loaded data produce an unsettled EMA. In ProOrder, increase PRELOADBARS when a long-period EMA drives the logic; on charts, values near the left edge should be ignored.
  • Comparing EMA and SMA of equal period. An N-period EMA has a shorter effective memory than an N-period SMA. Translating a strategy from one to the other while keeping the same period changes its behaviour.
  • Expecting a type parameter. Unlike Average, this function takes no second bracket argument. ExponentialAverage[10,1](close) is invalid; the type is already fixed.
  • Average, general moving average; Average[N,1] is the same EMA.
  • WeightedAverage, linear weighting, an intermediate between SMA and EMA.
  • WilderAverage, EMA variant with alpha = 1 / N, used inside RSI and ATR.
  • ZLEMA, zero-lag exponential moving average.
  • DEMA, double exponential moving average, further lag reduction.
  • TEMA, triple exponential moving average.
  • HullAverage, low-lag alternative built from weighted averages.
  • RSI, oscillator commonly smoothed with an EMA, as in Example 1.