# Harmonic MA

A Trend concept (Moving-average lineage) in the LuxAlgo Library, with 1 indicator implementation.

## What is a Harmonic MA?

A harmonic MA smooths price with the harmonic mean instead of the arithmetic mean: over an n-bar window it equals n divided by the sum of the reciprocals of the prices. It is one of the three Pythagorean means, and for any positive series it sits at or below the [geometric MA](https://www.luxalgo.com/library/concept/geometric-ma/), which in turn sits at or below the [SMA](https://www.luxalgo.com/library/concept/sma/); the three coincide only when every price in the window is identical.

Averaging reciprocals makes the harmonic mean disproportionately sensitive to the smallest values in the window: dips pull it down harder than spikes pull it up, and it is only defined for strictly positive data, since a value near zero would dominate it entirely. On ordinary price series, where values inside a window differ by small percentages, it plots almost on top of the SMA; differences become visible only when the window spans large swings. Statistically it is the p = -1 member of the power-mean family, with the arithmetic mean at p = 1 and the geometric mean as the limit at p = 0.

A worked example shows how quiet the difference usually is. For a window holding 98, 100 and 102 the arithmetic mean is exactly 100 while the harmonic mean is about 99.97, a gap invisible on any chart. Stretch the window to 50, 100 and 150 and the arithmetic mean stays at 100 while the harmonic mean drops to roughly 81.8. The divergence only becomes usable information when a window spans moves of tens of percent, which is why the harmonic MA distinguishes itself on crypto pairs, small caps and crash windows rather than on quiet large-cap charts.

In the LuxAlgo Library the harmonic mean mostly appears inside generalized moving average studies rather than as a standalone plot. BackQuant's Step Generalized Moving Average, the representative script here, exposes the power parameter directly, so a single input slides the same window smoothly from harmonic through geometric to arithmetic and beyond. That framing is the most honest way to think about the tool: not a rival signal engine to the [EMA](https://www.luxalgo.com/library/concept/ema/), but one point on a continuum of means whose choice encodes how much the average should respect dips versus spikes.

## How to identify a harmonic MA on a chart

A harmonic MA looks like any other smooth line, so identification is really about knowing when it genuinely differs from its arithmetic sibling and confirming the data it is fed is suitable.

1. Plot the harmonic MA and an SMA of the same length together; in a quiet range the two should be nearly indistinguishable, which confirms the implementation is correct rather than broken.
2. Watch what happens after a sharp selloff enters the window: the harmonic line should sag visibly below the SMA, because reciprocal averaging lets the low prints dominate the calculation.
3. Check the ordering. At every bar the harmonic mean must sit at or below the geometric mean, which sits at or below the arithmetic; any crossing between the three signals a calculation error.
4. Confirm the input is strictly positive raw price. Feeding returns, spreads that cross zero or oscillator values breaks the math, since a single near-zero value drags the mean toward zero.
5. If the script is a generalized mean, sweep the power input from 1 down to -1 and watch the line lean progressively toward the lows; the harmonic MA is the p = -1 endpoint of that sweep.

## How it's calculated

A moving average that takes the harmonic mean of the last n prices, giving lower prices more influence than an arithmetic average does.

```
R_t = 1 / P_t
HarmonicMA_t = n / Σ_(i=0..n-1) R_(t-i)
Equivalently: HarmonicMA_t = 1 / SMA_n(R_t)

  P_t: input price at bar t (close by default)
  R_t: reciprocal of the input price at bar t
  n: lookback length in bars (varies by platform; commonly 14)
  i: bar offset within the window, i = 0 for the current bar
  t: bar index
  HarmonicMA_t: harmonic mean moving average at bar t
  SMA_n(R_t): simple moving average of R_t over the last n bars
```

For positive inputs the harmonic mean never exceeds the geometric or arithmetic mean, so the line sits at or below an SMA of the same length and damps upward spikes.

The calculation is undefined if any price in the window is zero and unstable for prices near zero, so it suits price series rather than series that cross zero.

## How traders use it

- As a variant smoother in generalized-mean studies that sweep the power parameter to compare arithmetic, geometric and harmonic responses on the same series.
- For averaging ratio-like series (valuation multiples, spreads, rates), where the harmonic mean is often the statistically appropriate average and the arithmetic mean overstates.
- As a conservative baseline when downside sensitivity is wanted: the line discounts upside outliers within its window rather than chasing them.
- As a drop-in leg in [moving average crossovers](https://www.luxalgo.com/library/concept/moving-average-crossovers/) research, where swapping the slow leg to a harmonic mean makes bearish crosses trigger slightly earlier after sharp dips; treat any improvement as something to verify, not assume.
- As the midline of an [MA envelope](https://www.luxalgo.com/library/concept/ma-envelope/) when the study should lean toward the lower half of recent trade, keeping the band center conservative in volatile downtrends.

## Harmonic MA vs other moving averages

- **SMA** (https://www.luxalgo.com/library/concept/sma/): Same window, same lag, different mean. The SMA weights every price equally in level terms; the harmonic mean works in reciprocal space, so dips pull it down more than rallies lift it. On typical windows the two overlap almost exactly.
- **EMA** (https://www.luxalgo.com/library/concept/ema/): The EMA changes the weighting through time, favoring recent bars to cut lag. The harmonic MA keeps flat weights and changes the type of mean instead. They answer different questions, and a harmonic average of exponentially weighted terms is a legitimate hybrid.
- **Ehlers SuperSmoother** (https://www.luxalgo.com/library/concept/ehlers-supersmoother/): The SuperSmoother is a filter-design solution that targets passband behavior and minimal aliasing. The harmonic MA is a statistics-first choice about outlier treatment. For lag and noise control the filter wins; for principled averaging of ratios the mean wins.

## FAQ

### How is a harmonic moving average calculated?

Invert each of the last n prices, average those reciprocals, then invert again: equivalently, n divided by the sum of 1/price across the window. It requires strictly positive inputs, since a zero breaks the reciprocal and values near zero drag the mean sharply lower. Weighted versions exist, but the plain form is the direct harmonic-mean analogue of a simple moving average.

### When should you use a harmonic mean instead of an SMA on charts?

Rarely for plain price, where the two are nearly indistinguishable inside typical windows. The harmonic mean earns its place when averaging ratios (valuation multiples, spread ratios, rates), where it is often the mathematically apt mean, or when you deliberately want a smoother that leans toward the low values in the window. It is not a lag-reduction technique; its lag matches the SMA's.

### Why is the harmonic mean always the lowest of the three Pythagorean means?

Because averaging reciprocals gives small values outsized influence. A single low price produces a large reciprocal that dominates the sum, dragging the final inverted result down. The arithmetic mean treats a dip and a spike of equal size symmetrically, the geometric mean partially discounts the spike, and the harmonic mean discounts it hardest, which fixes the ordering harmonic at or below geometric at or below arithmetic for any positive data.

### Can you apply a harmonic MA to returns or oscillator values?

No. The harmonic mean requires strictly positive inputs: a zero return breaks the reciprocal outright, and any value near zero drags the average toward zero regardless of the rest of the window. Percent returns, z-scores and oscillators that cross zero are all unsuitable. Raw prices, volumes and ratio series such as valuation multiples are the natural domain; weighting by activity is a separate axis entirely, which is what [VWMA](https://www.luxalgo.com/library/concept/vwma/) changes instead.

### What is a generalized or power moving average?

A family that computes the mean of prices raised to a power p, then takes the p-th root. Setting p = 1 gives the arithmetic mean, p = -1 the harmonic, and the limit at p = 0 the geometric; pushing p above 1 leans the average toward the highs instead. Scripts like the Step Generalized Moving Average expose p as an input, turning the choice of mean into a single tunable parameter rather than a philosophical commitment.

### Does a harmonic MA reduce lag compared with an SMA?

No. Lag comes from the window, not the mean type, and both averages weight the same n bars. The harmonic version shifts the line's level, leaning it toward recent lows, but turns arrive on the same schedule. Traders who want faster response should look at recency weighting or [adaptive lookbacks](https://www.luxalgo.com/library/concept/adaptive-lookback-ma/) rather than at a different Pythagorean mean.

## Implementations in the Library

- Harmonic MA (LuxAlgo): https://www.luxalgo.com/library/indicator/harmonic-ma/

## Related concepts

- SMA: https://www.luxalgo.com/library/concept/sma/
- EMA: https://www.luxalgo.com/library/concept/ema/
- Adaptive-lookback MA: https://www.luxalgo.com/library/concept/adaptive-lookback-ma/
- MA Envelope: https://www.luxalgo.com/library/concept/ma-envelope/
- SWMA: https://www.luxalgo.com/library/concept/swma/
- RMA: https://www.luxalgo.com/library/concept/rma/
- HMA: https://www.luxalgo.com/library/concept/hma/
- KAMA: https://www.luxalgo.com/library/concept/kama/
- JMA: https://www.luxalgo.com/library/concept/jma/
- ZLEMA: https://www.luxalgo.com/library/concept/zlema/

---

Source: https://www.luxalgo.com/library/concept/harmonic-ma/ (LuxAlgo Library, the encyclopedia of trading & technical analysis). Free to use with attribution: https://www.luxalgo.com/library/license/