Reflex Oscillator

Calculate Ehlers’ Reflex or Trendflex: zero-lag oscillators that show the cycle (Reflex) or the trend (Trendflex) of the prices in units of their own recent size.

Both of Ehlers’ (2020) oscillators smooth the prices with a SuperSmoother over half the window and sum the differences between the latest smoothed price and each smoothed price over the window. Trendflex keeps those differences as they are, so it measures how far the price has moved away from its recent path: the trend. Reflex first takes out the straight line from the smoothed price a window ago to the latest one, which leaves only the curvature of the path: the cycle, without the lag of a moving average. Each sum is divided by the root of its exponentially weighted mean square, so both swing around zero in standard units; a turn of the Reflex marks a turn of the cycle and a Trendflex above (below) zero an uptrend (downtrend).

The Oscillator is the Reflex, with the Reflex Sum as Sum, or the Trendflex, with the Trendflex Sum as Sum.

The formula is as follows:

\[\text{Filter} = \text{SuperSmoother}\left(\text{Price}, \frac{\text{Window}}{2}\right)\] \[\text{Slope} = \frac{\text{Filter}_{t-\text{Window}} - \text{Filter}}{\text{Window}}\] \[\text{Reflex Sum} = \frac{\sum_{k=1}^{\text{Window}} (\text{Filter} + k \cdot \text{Slope} - \text{Filter}_{t-k})}{\text{Window}}\] \[\text{Trendflex Sum} = \frac{\sum_{k=1}^{\text{Window}} (\text{Filter} - \text{Filter}_{t-k})}{\text{Window}}\] \[\text{Mean Square} = 0.04 \cdot \text{Sum}^{2} + 0.96 \cdot \text{Mean Square}_{t-1}\] \[\text{Oscillator} = \frac{\text{Sum}}{\sqrt{\text{Mean Square}}}\]

Also known as: Reflex, Trendflex, Ehlers Reflex, Ehlers Trendflex, zero-lag indicator.

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()

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

What was Ehlers' Reflex oscillator for Apple, Microsoft and the S&P 500 ETF over the last five trading days of 2025, with data from 2021?

Which returns:

Parameters

get_reflex_oscillator 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 sum, twice the critical period of the SuperSmoother. Defaults to 20, as in Ehlers’ listing.20
methodstrThe oscillator. Options are: “reflex” (Reflex, the cycle), “trendflex” (Trendflex, the trend). Defaults to “reflex”."reflex"
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 Reflex or Trendflex. 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 Ehlers, J.F. (2020). “Reflex: A New Zero-Lag Indicator.” Technical Analysis of Stocks & Commodities, 38(2), 12-17.
  • Library Referenced against pandas-ta’s reflex
  • Library Shares similar logic as pandas-ta’s trendflex
Share