Triangular Moving Average

The Triangular Moving Average (TMA) is a simple moving average of a simple moving average, which gives the prices in the middle of the window the largest weight and the oldest and latest prices the smallest.

The formula for the Triangular Moving Average is as follows:

\[\text{TMA} = \text{SMA}(\text{SMA}(\text{Close}, n_{1}), n_{2})\]

Where SMA(x, k) is the simple moving average of x over k periods and \(n_{1}\) and \(n_{2}\) split the n periods of the window: both (n + 1) / 2 for an odd n, n / 2 and n / 2 + 1 for an even n. The weights rise and fall linearly, 1, 2, …, 2, 1, so the TMA is also called the symmetric weighted moving average. It is smoother than an SMA of the same length, at the cost of more lag.

A moving average smooths the price by averaging it over the last n periods, so that the trend shows through the noise of single periods. It is the oldest and most widely used trend indicator: the direction of the average shows the direction of the trend, the price above (below) it an uptrend (downtrend), and other indicators, from the MACD to the Bollinger Bands, are built on it. Every moving average trades smoothness against lag: the more periods it averages, the smoother it is and the later it turns after the price. The averages differ in how they weight the prices within the window and whether they adapt their speed to the market, each a different answer to that trade-off.

Also known as: TRIMA, TMA, SWMA, symmetric weighted moving average.

In the Finance Toolkit this is get_moving_average with method="triangular", the same function as Moving Average.

Example · ^GSPC · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_moving_average:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["^GSPC"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_moving_average(method="triangular", window=50)

Which returns:

References

  • Paper Achelis, S.B. (2000). “Technical Analysis from A to Z.” 2nd edition, McGraw-Hill.
  • Library Referenced against TA-Lib’s TRIMA (Triangular Moving Average)
  • Library Referenced against pandas-ta-classic’s swma (Triangular Moving Average)
Share