Fractal Adaptive Moving Average

The Fractal Adaptive Moving Average (FRAMA) of John Ehlers (2005) adapts its speed to the fractal dimension of the price: quick when the price trends, slow when it moves back and forth.

The formula for the Fractal Adaptive Moving Average works on the median price, the middle of each period’s high and low:

\[\text{Median Price} = \frac{\text{High} + \text{Low}}{2}\]

It measures the range of the price over the latest half of the window of n periods (\(N_{1}\)), the half before (\(N_{2}\)) and the whole window (\(N_{3}\)), each per period, with Max(x, k) and Min(x, k) the highest and lowest value of x over the last k periods and \(h = n / 2\):

\[N_{1} = \frac{\text{Max}(\text{High}, h) - \text{Min}(\text{Low}, h)}{h}\] \[N_{2} = N_{1,t-h}\] \[N_{3} = \frac{\text{Max}(\text{High}, n) - \text{Min}(\text{Low}, n)}{n}\]

Comparing the ranges of the halves with that of the whole window gives the fractal dimension D, which sets the smoothing factor alpha:

\[D = \frac{\log\left(N_{1} + N_{2}\right) - \log\left(N_{3}\right)}{\log\left(2\right)}\] \[\alpha = \exp\left(-4.6 \cdot (D - 1)\right)\]

The FRAMA is an EMA of the median price with that smoothing factor:

\[\text{FRAMA} = \alpha \cdot \text{Median Price} + (1 - \alpha) \cdot \text{FRAMA}_{t-1}\]

Where FRAMA(t-1) is the average of the period before. The dimension runs from 1, a price that moves in a straight line, to 2, a price that fills the plane as it moves back and forth, and alpha from 1 to 0.01 with it (Ehlers, 2005): the FRAMA follows a trend closely and flattens in a sideways market.

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: FRAMA.

In the Finance Toolkit this is get_moving_average with method="fractal_adaptive", 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="fractal_adaptive", window=50)

Which returns:

References

  • Paper Ehlers, J.F. (2005). “Fractal Adaptive Moving Averages.” Technical Analysis of Stocks & Commodities, 23(10), 81-82.
  • Library Referenced against TA-Lib’s FRAMA (Fractal Adaptive Moving Average)
  • Library Referenced against finta’s FRAMA (Fractal Adaptive Moving Average)
Share