# Harmonic MA

Harmonic MA is an indicator on [Vela](https://vela.luxalgo.com/chart), our next-generation charting platform, written in Pine Script®.

Smooths price with the harmonic mean, the window length divided by the sum of reciprocal prices, over 20 bars by default and next to a same-length SMA for comparison. Slope coloring, a price/MA gradient fill and crossing alerts carry the read, while a dashboard quotes the harmonic line's percentage gap to its arithmetic sibling and flags windows holding non-positive data.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Apr 9, 2026.
- Access: free.
- Concepts: [Harmonic MA](https://www.luxalgo.com/library/concept/harmonic-ma/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=kznyme5vmh6usmi944y1fs3w
- Page: https://www.luxalgo.com/library/indicator/harmonic-ma/

**Harmonic MA** is the definitive standalone build of the [harmonic MA](https://www.luxalgo.com/library/concept/harmonic-ma/): each bar it inverts the last 20 source values, averages the reciprocals and inverts the result, handing the smallest window values outsized influence. Dips drag the line down harder than spikes lift it, and for positive data it holds at or under the same-length SMA plotted beside it: nearly identical through quiet ranges, sagging visibly once a steep selloff lands inside the window. Slope coloring, a price gradient fill and a dashboard reporting the gap to the SMA complete the tool.

## How to Trade the Harmonic MA?

- **Rising line**: the slope turned positive. The bullish color and the Harmonic MA Slope Up alert mark the smoother's trend read.
- **Price above the line**: the bullish side of a deliberately conservative baseline, since the harmonic mean refuses to chase upside outliers.
- **Gap to SMA widening**: the window now spans large swings, a stress gauge this pair of lines measures directly.
- **Bearish price cross**: after sharp dips this fires slightly earlier than against an arithmetic baseline, because the line leans toward the window's lows.

Among the [trend smoothers](https://www.luxalgo.com/library/family/trend/) this one changes the mean, not the schedule; the Vs SMA row quantifies the sag in percent.

## Harmonic MA Settings

- **Source** (default close): must be strictly positive. Prices, volumes or ratio-like series, never returns or oscillators that cross zero.
- **Harmonic Length** (default 20): window size N in H = N / sum of reciprocals.
- **SMA — Same Length** (default enabled): the arithmetic comparison line.
- **Show Dashboard** (default enabled): length, gap, slope and price position.
- **Slope Trend Coloring** (default enabled): color the line by slope, or draw it in the neutral color.
- **Style toggles**: gradient fill on, crossing markers off, line width 2.

## Frequently Asked Questions

### How does the Harmonic MA differ from a Sine-Weighted MA?
A [Sine-Weighted MA](https://www.luxalgo.com/library/indicator/sine-weighted-ma/) changes which bars matter, emphasizing the middle of the window through a sine profile. The harmonic MA keeps equal weights but changes the mean itself, shifting the line's level toward the window's lows rather than reshaping its timing.

### Is the harmonic mean faster than an SMA?
No. It turns when a same-length SMA turns; the mean type moves the level, not the lag.

### What happens if the source touches zero or goes negative?
The reciprocal math becomes undefined, so any window holding a non-positive value plots nothing, the dashboard warns, and the Non-Positive Input alert fires. Feed it raw prices or other strictly positive series.

## Related indicators

- [Trend Regularity Adaptive Moving Average](https://www.luxalgo.com/library/indicator/trend-regularity-adaptive-moving-average/) (TRAMA): markdown at https://www.luxalgo.com/library/indicator/trend-regularity-adaptive-moving-average.md
- [Machine Learning Moving Average](https://www.luxalgo.com/library/indicator/machine-learning-moving-average/) (Adaptive-lookback MA): markdown at https://www.luxalgo.com/library/indicator/machine-learning-moving-average.md
- [ZLEMA](https://www.luxalgo.com/library/indicator/zlema/) (Trend): markdown at https://www.luxalgo.com/library/indicator/zlema.md
- [Moving Average Converging](https://www.luxalgo.com/library/indicator/moving-average-converging/) (EMA): markdown at https://www.luxalgo.com/library/indicator/moving-average-converging.md
- [MLMA](https://www.luxalgo.com/library/indicator/mlma/) (Trend): markdown at https://www.luxalgo.com/library/indicator/mlma.md
- [Volume-adjusted MA](https://www.luxalgo.com/library/indicator/volume-adjusted-ma/) (Trend): markdown at https://www.luxalgo.com/library/indicator/volume-adjusted-ma.md
- [JMA](https://www.luxalgo.com/library/indicator/jma/) (Trend): markdown at https://www.luxalgo.com/library/indicator/jma.md
- [T3](https://www.luxalgo.com/library/indicator/t3/) (Trend): markdown at https://www.luxalgo.com/library/indicator/t3.md

---

Source: https://www.luxalgo.com/library/indicator/harmonic-ma/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
