Indicators/probuilder · probacktest · proorder · proscreener

Average

Average in ProBuilder returns a moving average of any series, with an optional type argument selecting SMA, EMA, WMA, Wilder, Hull, and more. Examples.

Syntax

probuilder
Average[N](price)
Average[N,M](price)

Parameters

NameTypeDefaultDescription
Ninteger20Number of bars in the average. Shorter periods track price closely; longer periods smooth more and lag more.
Minteger0Optional average type selector. See the table below.
priceprice sourcecloseThe series to average. Accepts any price constant or custom variable, including other indicators.

Values for M:

MAverage type
0Simple Moving Average (SMA)
1Exponential Moving Average (EMA)
2Weighted Moving Average (WMA)
3Wilder's Moving Average
4Triangular Moving Average
5End Point Moving Average
6Time Series Moving Average
7Hull Moving Average (ProRealTime v11 and later)
8Zero-Lag Moving Average (ProRealTime v11 and later)

Formula

code
SMA = (price + price[1] + ... + price[N-1]) / N

With M omitted or 0, the result is the arithmetic mean of the last N values. Each other M value applies the weighting scheme of the corresponding average type; the dedicated instructions (ExponentialAverage, WeightedAverage, WilderAverage, and so on) document those definitions.

How it works

Average is the general-purpose smoothing function of ProBuilder. On every bar it recomputes the mean of the most recent N values of the given series, producing a line that filters bar-to-bar noise at the cost of reacting to changes with a delay proportional to N.

The second bracket argument turns one function into nine. Average[20,1](close) is equivalent to ExponentialAverage[20](close), Average[20,3](close) to WilderAverage[20](close), and so on. This is convenient when the average type itself is a variable, for example when an optimizer or an indicator setting should switch between SMA and EMA without rewriting code.

The input does not have to be a price. Any numeric series works, so Average is routinely used to smooth oscillators, volume, spreads, or the output of other calculations.

Examples

Example 1, Fast and slow simple averages (Indicator)

probuilder
// Plot a 7-period and a 20-period simple moving average
FastMA = Average[7](Close)
SlowMA = Average[20](Close)
RETURN FastMA coloured(221,33,33), SlowMA coloured(35,194,57)

Draws two SMAs of the close, the fast one in red and the slow one in green. The pair visualises short-term momentum against the broader drift.

Example 2, Moving average crossover system (ProOrder)

probuilder
// Reverse position on each crossover of the 20 and 50 SMA
fastMA = Average[20](close)
slowMA = Average[50](close)

IF fastMA CROSSES OVER slowMA THEN
  BUY 1 CONTRACT AT MARKET
ENDIF
IF fastMA CROSSES UNDER slowMA AND LongOnMarket THEN
  SELL AT MARKET
ENDIF

The strategy holds a long position while the 20-period average is above the 50-period average and exits when the relationship inverts, the minimal template for trend-following logic.

Example 3, Distance from the 200-bar average (ProScreener)

probuilder
// List instruments trading above their 200-period average
ma200 = Average[200](close)
gap = (close / ma200 - 1) * 100
SCREENER[close > ma200](gap AS "% above MA200")

Filters the watchlist to instruments above their long-term average and ranks them by the percentage gap, a simple relative-strength scan.

Interpretation

Price versus the average. Price holding above a rising average is the standard definition of an uptrend on that horizon; price below a falling average, a downtrend. The 50-period and 200-period averages are the most widely watched reference lines.

Crossovers. A fast average crossing above a slow one signals that recent prices are outpacing older ones, a momentum shift. Crossovers lag by construction, so they confirm trends rather than anticipate them, and they whipsaw in sideways markets.

Slope. The direction of the average itself is often more informative than a single crossing. A flat average indicates a range, where crossover signals degrade sharply.

Common errors and gotchas

  • Wrong bracket type. Average(20, close) raises a syntax error. Period and type go in square brackets, the series in parentheses: Average[20,1](close).
  • Invalid type selector. M outside 0 to 8 is not a valid average type. Values 7 and 8 additionally require ProRealTime v11 or later.
  • Assuming EMA by default. With one argument the function always returns a simple average. Code ported from platforms whose default is exponential will behave differently until ,1 is added.
  • Crossover systems in ranges. Two averages of a sideways series cross repeatedly. Without a trend or volatility filter, the crossover template in Example 2 accumulates losing trades in flat markets.
  • ExponentialAverage, dedicated EMA, equivalent to M = 1.
  • WeightedAverage, linearly weighted average, equivalent to M = 2.
  • WilderAverage, Wilder's smoothing, equivalent to M = 3.
  • TriangularAverage, doubly smoothed average, equivalent to M = 4.
  • EndPointAverage, regression end point average, equivalent to M = 5.
  • TimeSeriesAverage, time series average, equivalent to M = 6.
  • HullAverage, low-lag Hull average, equivalent to M = 7.
  • ZLEMA, zero-lag exponential average, equivalent to M = 8.
  • RSI, oscillator frequently smoothed with Average.