Trend Intensity Index

Calculate Pee’s Trend Intensity Index (TII): the share of the recent deviations from a long moving average that were above it, from 0 to 100, which shows how strong a trend is.

The Trend Intensity Index of Pee (2002) looks at the distance of each close to a long simple moving average over the last deviation_window periods and divides the sum of the distances above the average by the sum of all distances. Above 80 the prices hold well above their average, a strong uptrend; below 20 a strong downtrend; around 50 there is no trend. The signal line is an exponential moving average of the index.

The formula is as follows:

\[\text{Deviation} = \text{Close} - \text{SMA}(\text{Close}, \texttt{window})\] \[\text{Positive Sum} = \text{Sum}\left(\max\left(\text{Deviation}, 0\right), \texttt{deviation\_window}\right)\] \[\text{Negative Sum} = \text{Sum}\left(\max\left(-\text{Deviation}, 0\right), \texttt{deviation\_window}\right)\] \[\text{TII} = \frac{100 \cdot \text{Positive Sum}}{\text{Positive Sum} + \text{Negative Sum}}\] \[\text{Signal Line} = \text{EMA}(\text{TII}, \texttt{signal\_window})\]

Also known as: TII, Trend Intensity Index.

Example · MSFT · 2021 to 2025

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

from financetoolkit import Toolkit

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

toolkit.technicals.get_trend_intensity_index().xs("MSFT", level=1, axis="columns")

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

What were Microsoft's Trend Intensity Index and its signal line over the last five trading days of 2025, with data from 2021?

Which returns:

Parameters

get_trend_intensity_index accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Options are: “intraday” (intraday prices), “daily” (daily prices), “weekly” (weekly prices), “monthly” (monthly prices), “quarterly” (quarterly prices), “yearly” (yearly prices). Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”."Close"
windowintThe number of periods of the moving average. Defaults to 60, as Pee uses.20
deviation_windowintThe number of periods of the deviations. Defaults to 30, half the window, as Pee uses.30, half the window, as Pee uses
signal_windowintThe number of periods of the signal line. Defaults to 9.9
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the Trend Intensity Index. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
transformstr | list[str] | NoneTime series steps applied in order, such as “sma:12” (moving average), “ema:12”, “std:12”, “zscore:60”, “percentile:120”, “yoy”, “pct_change:3,annualize:3”, “log”, “diff”, “cumsum” or “hp_trend” and “hp_cycle” (Hodrick-Prescott), before growth. A window needs that many periods of history, so the first periods can be empty. Defaults to None.None
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Pee, M.H. (2002). “Trend Intensity Index.” Technical Analysis of Stocks & Commodities, 20(6), 52-56.
Share