MomentumPine Script v6

Impulse MACD Pine Script — Complete TradingView Guide

The Impulse MACD is an advanced momentum oscillator for Pine Script v6 that upgrades the classic MACD by replacing standard EMAs with a Zero-Lag EMA (ZLEMA) of the typical price (hlc3) and Smoothed Moving Averages (SMMA) of the high and low. The result is a four-color histogram that encodes market regime: bright green for strong bullish momentum (price above both ZLEMA and SMMA high band), dark green for weakening upside, red for strong bearish momentum, and orange for neutral/consolidation. The default settings are lengthMA=34 and lengthSignal=9 — calibrated for swing trading on Daily and 4H charts. Unlike standard MACD, Impulse MACD explicitly models a zero-zone when price is inside the SMMA bands, giving traders a clear picture of when momentum has stalled. This guide covers the complete Pine Script v6 implementation, all configurable parameters with recommended ranges, three concrete Impulse MACD trading strategies, and a five-step guide to generating Impulse MACD scripts instantly with Pineify.

What Is the Impulse MACD?

The Impulse MACD is a momentum oscillator that combines a Zero-Lag EMA of the typical price with Smoothed Moving Averages of the high and low, used to identify trend regime, momentum strength, and early reversal signals on any liquid market. It was developed as an enhancement of Dr. Alexander Elder's Impulse System, first introduced in his 2002 book Come Into My Trading Room. Elder's original system used simple EMAs of the closing price; the Impulse MACD community implementation upgrades the calculation with ZLEMA and SMMA to reduce lag and improve regime clarity.

Core formula components:

  • SMMA (Smoothed Moving Average): smma = (smma[1] × (len−1) + src) / len — a weighted recursion that is smoother than SMA and less reactive than EMA. Applied to high and low separately to form dynamic bands (hi and lo).
  • ZLEMA (Zero-Lag EMA): zlema = 2×EMA(src,len) − EMA(EMA(src,len),len) — doubles the EMA and subtracts a second-order EMA to cancel the phase shift, producing a nearly lag-free moving average of hlc3 (mi).
  • Primary impulse (md): md = mi > hi ? (mi−hi) : mi < lo ? (mi−lo) : 0 — measures how far price has broken out of the SMMA band. Zero when price is inside the bands (consolidation).
  • Signal (sb): sb = SMA(md, lengthSignal) — a simple moving average of md, equivalent to the MACD signal line.
  • Secondary histogram (sh): sh = md − sb — the equivalent of the classic MACD histogram; positive when momentum is accelerating, negative when decelerating.

The Impulse MACD applies to all liquid asset classes: stocks, crypto, forex, and futures. It performs best in directionally trending markets and is less effective during low-volatility consolidation phases where price stays inside the SMMA bands (md remains at zero for extended periods). Best timeframes are 1H, 4H, and Daily charts. On Daily charts with the default 34/9 settings, Impulse MACD captures multi-day swing moves. On 1H charts with 21/8 settings, it works well for intraday trend-following in forex and crypto. On Weekly charts, a 55/9 setting aligns with Fibonacci-based cycle analysis.

Best Markets

Stocks · Crypto · Forex · Futures

Best Timeframes

1H, 4H, Daily

Overlay

No — separate oscillator panel

Impulse MACD Pine Script Code Example

The code below implements a complete Impulse MACD oscillator in Pine Script v6 using a ZLEMA of hlc3 and SMMA high/low bands, with a four-color regime histogram and a blue secondary histogram. To add it to TradingView, open the Pine Script editor with Alt+P, paste the entire code, and click Add to chart — the indicator will appear in a separate panel below the price chart. Adjust lengthMA and lengthSignal inside the p_ta_imacd(34, 9) call to tune sensitivity for your timeframe.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//@version=6
indicator(title="Impulse MACD", overlay=false, max_labels_count=500)

// Smoothed Moving Average (SMMA) — removes short-term noise
p_ta_f_smma(src, len) =>
    smma = 0.0
    smma := na(smma[1]) ? ta.sma(src, len) : (smma[1] * (len - 1) + src) / len
    smma

// Zero-Lag EMA (ZLEMA) — reduces EMA lag: 2*EMA(src,len) - EMA(EMA(src,len),len)
p_ta_f_zlema(src, len) =>
    ema1 = ta.ema(src, len)
    ema2 = ta.ema(ema1, len)
    2.0 * ema1 - ema2

// Impulse MACD core calculation
p_ta_imacd(simple int lengthMA, simple int lengthSignal) =>
    src = hlc3
    hi  = p_ta_f_smma(high, lengthMA)
    lo  = p_ta_f_smma(low,  lengthMA)
    mi  = p_ta_f_zlema(src, lengthMA)

    // Primary impulse line: deviation of ZLEMA from SMMA bands
    md = mi > hi ? (mi - hi) : mi < lo ? (mi - lo) : 0.0
    // Signal line: SMA of md
    sb = ta.sma(md, lengthSignal)
    // Secondary histogram: md minus signal
    sh = md - sb

    isStrongUp   = src > mi and src > hi
    isWeakUp     = src > mi and not (src > hi)
    isStrongDown = src < lo
    isWeakDown   = not isStrongUp and not isWeakUp and not isStrongDown

    [md, sh, sb, isStrongUp, isWeakUp, isStrongDown, isWeakDown]

// Default: lengthMA=34, lengthSignal=9
[p_ind_1_md, p_ind_1_sh, p_ind_1_sb,
 p_ind_1_isStrongUp, p_ind_1_isWeakUp,
 p_ind_1_isStrongDown, p_ind_1_isWeakDown] = p_ta_imacd(34, 9)

// Zero reference line
hline(0, "IMACD - Zero", color=color.new(#787B86, 50))

// Primary impulse histogram — color encodes market regime
plot(p_ind_1_md, title="IMACD",
     style=plot.style_histogram,
     color = p_ind_1_isStrongUp   ? color.rgb(0,   200, 83,  0) :
             p_ind_1_isWeakUp     ? color.rgb(67,  160, 71,  0) :
             p_ind_1_isStrongDown ? color.rgb(229, 57,  53,  0) :
                                    color.rgb(251, 140, 0,   0))

// Secondary histogram (md − signal)
plot(p_ind_1_sh, title="IMACD - Histo2",
     style=plot.style_histogram,
     color=color.rgb(30, 136, 229, 0))

// Signal line
plot(p_ind_1_sb, title="IMACD - Signal",
     color=color.rgb(109, 76, 65, 0), linewidth=1)

Chart Preview

Impulse MACD indicator Pine Script code example in TradingView — four-color regime histogram with ZLEMA and SMMA bands

Impulse MACD Parameters

ParameterDefault ValueDescriptionRecommended Range
lengthMA34The main lookback period applied to SMMA (high and low bands) and ZLEMA (hlc3). Controls how responsive the bands are to price changes. Smaller values create tighter bands and more frequent signals; larger values create wider bands and fewer, higher-quality signals.14–55 (common: 21, 34, 55)
lengthSignal9The SMA period applied to the primary impulse (md) to generate the signal line (sb). Controls secondary histogram speed — smaller values make the secondary histogram more reactive to short-term momentum shifts, larger values smooth it out.6–13 (most common: 8, 9)
sourcehlc3The price series fed into the ZLEMA calculation (mi). The default hlc3 (typical price: (high + low + close) / 3) reduces sensitivity to single-bar wicks. Can be overridden with close for a more standard reading.hlc3 (recommended), close
Zero Line0The reference level separating bullish (md > 0) from bearish (md < 0) regimes. When md = 0, price is inside the SMMA bands and the market is in a neutral or consolidating state with no meaningful momentum.Fixed at 0 (not adjustable)

Tuning Guide by Trading Style

  • Scalping (5m–15m charts): lengthMA 14–21, lengthSignal 6–8 — tighter bands for fast breakout detection in crypto and forex
  • Day trading (1H charts): lengthMA 21, lengthSignal 8 — balanced responsiveness for intraday trend capture with reduced false signals
  • Swing trading (4H–Daily charts): lengthMA 34, lengthSignal 9 — the default Elder-based setting; best for capturing multi-day momentum shifts
  • Position trading (Daily–Weekly charts): lengthMA 55, lengthSignal 9 — Fibonacci-aligned period for major trend identification in stocks and indices

Impulse MACD Trading Strategies

The Impulse MACD is most powerful as a regime filter — only entering trades when the histogram color confirms alignment between price, the ZLEMA, and the SMMA bands. Below are three concrete strategies with specific entry and exit conditions.

Strategy 1 — Regime Color Confirmation (Trend-Following)

Market environment: trending markets · Best timeframe: 4H, Daily

Enter long only when the Impulse MACD histogram turns bright green (strong up regime), confirming that price is above both the ZLEMA and the SMMA high band simultaneously. Combine with EMA(50) as a macro trend filter to avoid counter-trend entries. In Pine Script v6: ema50 = ta.ema(close, 50).

  1. Calculate Impulse MACD: [md, sh, sb, isStrongUp, isWeakUp, isStrongDown, isWeakDown] = p_ta_imacd(34, 9)
  2. Add macro filter: ema50 = ta.ema(close, 50)
  3. Long entry: isStrongUp and close > ema50 — histogram turns bright green AND price is above EMA 50
  4. Exit / avoid: histogram turns orange or red — regime has weakened; close or reduce position
  5. Stop loss: bar low of the entry candle or below the SMMA low band

Strategy 2 — Secondary Histogram Zero-Cross with ATR Filter

Market environment: trending markets · Best timeframe: 1H, 4H

The secondary histogram (sh = md − sb) crosses zero when momentum is accelerating or decelerating — equivalent to a MACD histogram sign change. Use ATR(14) above its 20-period SMA as a volatility gate to filter out flat-market false signals. In Pine Script v6: atr14 = ta.atr(14).

  1. Calculate volatility gate: atr14 = ta.atr(14); atrSma = ta.sma(atr14, 20); highVolatility = atr14 > atrSma
  2. Calculate Impulse MACD and extract sh (secondary histogram)
  3. Long entry: ta.crossover(sh, 0) and md > 0 and highVolatility — sh turns positive in a bullish md regime with elevated volatility
  4. Short entry: ta.crossunder(sh, 0) and md < 0 and highVolatility — sh turns negative in a bearish md regime
  5. Exit: sh crosses back below 0 (for longs) or above 0 (for shorts), indicating momentum is fading

Strategy 3 — Impulse MACD Divergence + Bollinger Bands

Market environment: trending markets approaching exhaustion · Best timeframe: 4H, Daily

When price makes a new high but the Impulse MACD primary histogram (md) makes a lower high, bearish divergence warns of trend exhaustion. Pair with Bollinger Bands(20, 2.0) — price closing outside the upper band while md diverges confirms the overextension. In Pine Script v6: [_, bbUpper, bbLower] = ta.bb(close, 20, 2.0).

  1. Calculate Bollinger Bands: [_, bbUpper, bbLower] = ta.bb(close, 20, 2.0)
  2. Calculate Impulse MACD (md is the primary impulse value)
  3. Bearish divergence: price makes a higher high AND close >= bbUpper AND md makes a lower high than the prior swing — momentum weakening at the top band
  4. Bullish divergence: price makes a lower low AND close <= bbLower AND md makes a higher low than the prior swing — selling pressure exhausting at the bottom band
  5. Entry confirmation: wait for the histogram to change regime color (e.g., red → orange) to confirm the reversal before entering

Disclaimer: The strategies above are for educational purposes only and do not constitute investment advice. Past performance does not guarantee future results. Always apply proper risk management and position sizing.

How to Generate the Impulse MACD Indicator in Pineify

  1. 1

    Open Pineify

    Go to pineify.app and sign in — a free account is sufficient to generate Impulse MACD Pine Script indicators.

  2. 2

    Click "New Indicator"

    Select "Indicator" as the script type from the creation menu on the dashboard.

  3. 3

    Describe the Impulse MACD configuration you want

    Type a prompt such as: "Generate an Impulse MACD indicator with lengthMA=34 and lengthSignal=9, using ZLEMA of hlc3 and SMMA of high/low, with four-color regime histogram." Pineify's AI Coding Agent generates the complete Pine Script v6 code in seconds.

  4. 4

    Copy to TradingView

    Click "Copy to TradingView" to copy the generated code, then open the TradingView Pine Script editor (Alt+P), paste the code, and click "Add to chart". The Impulse MACD will appear in a separate panel below the price chart.

  5. 5

    Adjust lengthMA and lengthSignal

    Modify the values inside the p_ta_imacd() call — for example, change 34 to 21 for day trading on 1H charts, or to 55 for weekly position trading — then re-add the indicator to your chart.

Frequently Asked Questions

Build Your Impulse MACD in Seconds

Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use Pine Script indicators — including Impulse MACD with ZLEMA, SMMA bands, four-color regime histograms, and custom lengthMA/lengthSignal settings — instantly for free.

Try Pineify Free