Calculate the Triangular Moving Average (TMA) for a given price series.

The Triangular Moving Average (TMA) is a smoothed version of the Simple Moving Average (SMA) that uses multiple SMAs to reduce noise and provide a smoother trendline.

The formula is as follows:

\[\text{For an odd window:}\;\; \text{Sub-window Length} = (\text{Window} + 1) / 2,\;\; \text{applied for both passes}\] \[\text{For an even window:}\;\; \text{the two passes use different sub-window lengths},\;\; \text{Window} / 2 \text{and Window} / 2 + 1 (\text{matching TA-Lib's TRIMA convention})\] \[\text{TMA} = \operatorname{SMA}(\operatorname{SMA}(\text{Close},\; \text{Sub-window Length} 1),\; \text{Sub-window Length} 2)\]

Also known as: TMA, triangular MA.

No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Triangular Moving Average (TMA) for you. Just ask in plain English.

Calculate the Triangular Moving Average (TMA) in Python

The Triangular Moving Average (TMA) is available in the Technicals module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_triangular_moving_average as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(tickers=["AAPL", "MSFT"])

toolkit.technicals.get_triangular_moving_average()

Which returns:

Date AAPL MSFT Benchmark
2026-06-18 561.385 762.584 1392.14
2026-06-22 560.145 750.16 1390.25
2026-06-23 557.359 741.177 1386.79
2026-06-24 555.068 732.927 1383.99
2026-06-25 550.257 722.897 1380.95
2026-06-26 547.116 717.071 1379.81
2026-06-29 544.476 711.315 1380.05
2026-06-30 544.317 707.263 1381.34
2026-07-01 544.691 705.519 1384.05
2026-07-02 546.424 705.539 1384.99

Parameters

get_triangular_moving_average accepts the following parameters:

  • period (str, optional): The time period to consider for historical data. Can be “daily”, “weekly”, “quarterly”, or “yearly”. Defaults to “daily”.
  • close_column (str, optional): The column name for closing prices in the historical data. Defaults to “Adj Close”.
  • window (int, optional): Number of periods for TMA calculation. The number of periods (time intervals) over which to calculate the TMA.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
  • growth (bool, optional): Whether to calculate the growth of the TMA. Defaults to False.
  • lag (int | list[int], optional): The lag to use for the growth calculation.
  • standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. Defaults to 1.

The Technicals module page introduces the module, and the sidebar lists all of its functions.

Share