TriangularAverage
TriangularAverage in ProBuilder returns a double smoothed simple moving average of price over N bars, producing an extra smooth trend line. Syntax, examples.
Syntax
TriangularAverage[N](price)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
N | integer | none | Total lookback period. Larger values give a smoother, slower line. |
price | price source | none | Series to smooth, typically close. Any price constant or custom variable is accepted. |
Formula
TMA = SMA[m](SMA[m](price))
where m is approximately (N + 1) / 2The smoothing is applied in two passes: a simple moving average of the raw data, then a simple moving average of that first average. The combined weighting scheme is triangular, bars in the middle of the window carry the most weight and weights taper off linearly toward both ends, which is where the name comes from.
How it works
A simple moving average weights every bar in its window equally, so a single outlier entering or leaving the window shifts the line noticeably. The triangular average suppresses this effect. Because the second pass averages the first, short spikes are diluted twice, and the resulting line is one of the smoothest of the classic moving average family.
The cost of the double smoothing is lag. A TMA turns after the equivalent simple average does, and well after price itself. It is therefore better suited to describing the established trend than to timing entries at reversals. In trending markets, the line's slope and the side of the line price trades on are the primary readings.
The period N behaves as with other averages: small values track price more closely, large values emphasise the longer cycle. Since the effective smoothing is double, a TMA of period 20 feels comparable to a noticeably longer simple average.
Examples
Example 1, Stepped trend line from a 50-bar TMA (Indicator)
// Hold the plotted value until the TMA moves at least 1% away from it
once ssMA = close
MA = TriangularAverage[50](close)
if(MA > ssMA + (MA/100)*1) THEN
ssMA = MA
ELSIF (MA < ssMA - (MA/100)*1) THEN
ssMA = MA
ELSE
ssMA = ssMA
ENDIF
RETURN ssMAThe 50-period triangular average is converted into a stepped line that only updates when the TMA drifts more than 1 percent from the last stored value. Minor wobbles in the average are ignored and the plot changes level only on meaningful moves.
Example 2, Price and TMA crossover system (ProOrder)
// Trend following on closes crossing the triangular average
tma = TriangularAverage[50](close)
IF close CROSSES OVER tma THEN
BUY 1 CONTRACT AT MARKET
ELSIF close CROSSES UNDER tma THEN
SELL AT MARKET
ENDIFBecause the TMA is very smooth, price crossings of the line occur less often than with a simple average of the same period, trading fewer but longer signals.
Example 3, Rising TMA scan (ProScreener)
tma = TriangularAverage[20](close)
SCREENER[tma > tma[5]] ((tma - tma[5]) AS "TMA slope")Returns instruments whose 20-period triangular average is higher than it was five bars ago, ranked by the size of the rise, a basic uptrend filter.
Interpretation
Standard moving average conventions apply. Price above a rising TMA indicates an uptrend, price below a falling TMA a downtrend, and a flat TMA a range. Because the line is double smoothed, its slope changes are rarer and more deliberate than those of other averages, which makes the TMA popular as a trend filter: take long signals from a faster tool only while the TMA rises, shorts only while it falls. Crossovers of price and TMA arrive late relative to the actual turn, so they confirm rather than anticipate reversals.
Common errors and gotchas
- Wrong bracket type. The period belongs in square brackets and the price in parentheses:
TriangularAverage[50](close). WritingTriangularAverage(50, close)is a syntax error. - Expecting timely reversal signals. The double smoothing makes the TMA one of the laggiest common averages. Entries taken on TMA turns occur well after the price reversal, which mean-reversion logic in particular should account for.
- Underestimating the effective period. A TMA of period
Nsmooths roughly like a considerably longer simple average. Porting a strategy fromAverage[N]toTriangularAverage[N]changes its character, re-tune the period. - Warm-up bars. Two averaging passes need roughly
Nbars of history before the output stabilises. Values on the earliest bars of the chart are unreliable.
Related instructions
Average, simple moving average, the single-pass baseline.ExponentialAverage, exponentially weighted average with less lag.WeightedAverage, linearly weighted average favouring recent bars.TimeSeriesAverage, regression based moving average.WilderAverage, Wilder's smoothing used inside RSI and ATR.HullAverage, moving average designed to minimise lag.DEMA, double exponential moving average, less lag than a double SMA.TEMA, triple exponential moving average.ZLEMA, zero-lag exponential moving average.
