Trendflex

The Trendflex keeps the differences between the latest smoothed price and each smoothed price of the window as they are, so it measures how far the price has moved away from its recent path: the trend.

The formula for the Trendflex first smooths the price with a two-pole SuperSmoother whose critical period is half the window of n periods:

\[\text{Filter} = \text{SuperSmoother}\left(\text{Price}, \frac{n}{2}\right)\]

It sums how far the latest smoothed price lies from each smoothed price of the window:

\[\text{Trendflex Sum} = \frac{\sum_{k=1}^{n} (\text{Filter} - \text{Filter}_{t-k})}{n}\]

It divides that sum by the root of its exponentially weighted mean square, its recent size:

\[\text{Mean Square} = 0.04 \cdot \text{Trendflex Sum}^{2} + 0.96 \cdot \text{Mean Square}_{t-1}\] \[\text{Trendflex} = \frac{\text{Trendflex Sum}}{\sqrt{\text{Mean Square}}}\]

Where Price is the close, Filter(t-k) the smoothed price k periods ago and SuperSmoother(x, k) Ehlers’ two-pole low-pass filter that removes the cycles shorter than k periods. A Trendflex above zero shows an uptrend and below zero a downtrend, and the further from zero, the stronger the trend relative to the recent moves.

John Ehlers (2020) designed the Reflex and Trendflex as oscillators without the lag of a moving average: both smooth the price with a SuperSmoother, compare the latest smoothed price with each smoothed price of the last n periods, and divide the result by its own recent size, so that they swing around zero in standard units whatever the price level or volatility. The Reflex shows the cycle of the price and the Trendflex its trend.

Also known as: Ehlers Trendflex, Trendflex indicator.

In the Finance Toolkit this is get_reflex_oscillator with method="trendflex", the same function as Reflex Oscillator.

Example · AAPL, MSFT · 2021 to 2025

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

from financetoolkit import Toolkit

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

toolkit.technicals.get_reflex_oscillator(method="trendflex")

Which returns:

References

  • Paper Ehlers, J.F. (2020). “Reflex: A New Zero-Lag Indicator.” Technical Analysis of Stocks & Commodities, 38(2), 12-17.
  • Library Shares similar logic as pandas-ta’s trendflex (Trendflex)
Share