Indicator · Pine Script v6 · Own pane

Ehlers Moving Average Difference with Hann (MADH)

by mihakralj

This indicator plots the Ehlers moving average difference with Hann windowing in a separate pane.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code57
Settings3inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

57 lines of Pine Script v6 from lib/oscillators/madh/madh.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

madh.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Ehlers Moving Average Difference with Hann (MADH)", "MADH", overlay = false)

//@function Ehlers Moving Average Difference with Hann — dual Hann FIR filter
//          difference expressed as a percentage. Zero-crossing oscillator.
//@param source Series to analyze (typically Close)
//@param shortLength Short Hann FIR window length (>= 1)
//@param dominantCycle Dominant cycle period (>= 2)
//@returns MADH oscillator value (percentage, zero-centered, unbounded)
//@reference Ehlers, J.F. (2021). "The MAD Indicator, Enhanced."
//           Technical Analysis of Stocks & Commodities, Nov 2021.
//@optimized O(LongLength) per bar — FIR scan over two Hann-weighted windows
madh(series float source, simple int shortLength, simple int dominantCycle) =>
    if shortLength < 1
        runtime.error("ShortLength must be at least 1")
    if dominantCycle < 2
        runtime.error("DominantCycle must be at least 2")

    int longLength = int(shortLength + dominantCycle / 2)

    // --- Short Hann FIR filter ---
    float filt1 = 0.0
    float coef1 = 0.0
    for k = 1 to shortLength
        float w = 1.0 - math.cos(2.0 * math.pi * k / (shortLength + 1))
        filt1 += w * nz(source[k - 1])
        coef1 += w
    if coef1 != 0.0
        filt1 := filt1 / coef1

    // --- Long Hann FIR filter ---
    float filt2 = 0.0
    float coef2 = 0.0
    for k = 1 to longLength
        float w = 1.0 - math.cos(2.0 * math.pi * k / (longLength + 1))
        filt2 += w * nz(source[k - 1])
        coef2 += w
    if coef2 != 0.0
        filt2 := filt2 / coef2

    // --- MADH = percentage difference ---
    float result = filt2 != 0.0 ? 100.0 * (filt1 / filt2 - 1.0) : 0.0
    result

// ── Inputs ──
int   p_short = input.int(8, "Short Length", minval = 1)
int   p_cycle = input.int(27, "Dominant Cycle", minval = 2)
float p_src   = input.source(close, "Source")

// ── Calculation ──
float out = madh(p_src, p_short, p_cycle)

// ── Plot ──
plot(out, "MADH", color.yellow, 2)
hline(0, "Zero", color.gray)

Overview

Ehlers Moving Average Difference with Hann (MADH) runs two Hann FIR filters on the chosen source: a short window and a longer window whose length is the short length plus half the dominant cycle. The oscillator is the percentage difference of the short filter relative to the long filter and is centered on zero. A horizontal line marks zero. Short length, dominant cycle, and source control the calculation. It does not generate trade entries or exits.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Short Lengthint8p_short
Dominant Cycleint27p_cycle
Sourcesourceclosep_src
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Derivative Oscillator

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

MACD

by Alorse
330 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of MACD

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers