Indicator · Pine Script v6 · Own pane

MACD Integration for GemHunter (Smoothed)

by Finland93

This indicator calculates a smoothed, volume-weighted MACD oscillator displayed in a separate pane.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code149
Settings17inputs
LicenceMPL-2.0
Last update4 months ago29 Jun 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

149 lines of Pine Script v6 from GemHunter/MACD-integration.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

MACD-integration.pine
//@version=6
// ════════════════════════════════════════════════════════════════════════════════
//  MACD Integration for GemHunter  (Smoothed · Volume-aware · MTF · Divergence)
//  Companion oscillator for the GemHunter trend-regime indicator.
//  https://github.com/Finland93/GemHunter
//  Educational tool, not financial advice. Backtest before using.
// ════════════════════════════════════════════════════════════════════════════════
indicator(title="MACD Integration for GemHunter (Smoothed)", shorttitle="GemHunter MACD+", overlay=false)

// ── Inputs ──────────────────────────────────────────────────────────────────────
source        = input.source(close, title="Source")
fastLength    = input.int(12,  title="Fast Length",   minval=1)
slowLength    = input.int(26,  title="Slow Length",   minval=1)
signalLength  = input.int(9,   title="Signal Length", minval=1)
maType        = input.string(defval="SuperSmoother", title="MA Type", options=["EMA","DEMA","TEMA","SuperSmoother","RMA"], tooltip="Smoothing applied to the fast/slow averages. SuperSmoother (Ehlers) gives low lag with little noise; EMA reproduces the classic MACD.")
useVolume     = input.bool(true,  title="Use Volume Factor", tooltip="Scales MACD by relative volume so low-volume drift is de-emphasised. Safely ignored on instruments without volume.")
volSmaLen     = input.int(50,     title="Volume SMA Len",   minval=1)
volEmaLen     = input.int(10,     title="Volume EMA Len",   minval=1)
volCap        = input.float(1.8,  title="Volume Factor Cap (x)", minval=0.5, step=0.1, tooltip="Clamps the volume factor to [1/cap, cap] so a single spike can't dominate.")
mtfTF         = input.timeframe("", title="MTF Confirm TF (optional)", tooltip="Leave blank to disable. When set, crosses must agree with this higher timeframe's MACD.")
showHist      = input.bool(true,  title="Show Histogram")
showCross     = input.bool(true,  title="Show Cross Dots")
showDiv       = input.bool(false, title="Show Divergence (pivot-based)")
showLabel     = input.bool(true,  title="Show Trend Label")
// Extra visual smoothing (EMA passes; 0 = off)
macdSmoothLen = input.int(3, title="Extra MACD Smooth",   minval=0)
sigSmoothLen  = input.int(3, title="Extra Signal Smooth", minval=0)
histSmoothLen = input.int(2, title="Extra Hist Smooth",   minval=0)

// ── Moving-average helpers ───────────────────────────────────────────────────────
dema(src, l) => 2 * ta.ema(src, l) - ta.ema(ta.ema(src, l), l)

tema(src, l) =>
    e1 = ta.ema(src, l)
    e2 = ta.ema(e1, l)
    e3 = ta.ema(e2, l)
    3 * (e1 - e2) + e3

// Ehlers 2-pole SuperSmoother
superSmoother(src, length) =>
    PI = 3.141592653589793
    a1 = math.exp(-1.414 * PI / length)
    b1 = 2 * a1 * math.cos(1.414 * PI / length)
    c2 = b1
    c3 = -a1 * a1
    c1 = 1 - c2 - c3
    var float filt = na
    filt := na(filt[1]) ? src : c1 * (src + nz(src[1])) / 2 + c2 * nz(filt[1]) + c3 * nz(filt[2])
    filt

ma(src, l) =>
    switch maType
        "EMA"  => ta.ema(src, l)
        "DEMA" => dema(src, l)
        "TEMA" => tema(src, l)
        "RMA"  => ta.rma(src, l)
        => superSmoother(src, math.max(l, 2))

emaIf(src, l) => l > 0 ? ta.ema(src, l) : src

// ── Non-repainting HTF wrapper (confirmed values only) ───────────────────────────
htfConfirm(expr) =>
    mtfTF == "" ? expr : request.security(syminfo.tickerid, mtfTF, barstate.isconfirmed ? expr : nz(expr[1]), barmerge.gaps_off, barmerge.lookahead_off)

// ── Core MACD (smoothed + volume-normalised) ─────────────────────────────────────
fastMA  = ma(source, fastLength)
slowMA  = ma(source, slowLength)
macdRaw = fastMA - slowMA

// Volume factor with division-by-zero / no-volume guard
volSma  = ta.sma(volume, volSmaLen)
volNorm = na(volSma) or volSma == 0 ? 1.0 : volume / volSma
volFac  = useVolume ? math.min(volCap, math.max(1 / volCap, ta.ema(volNorm, volEmaLen))) : 1.0

// Build the MACD, then derive the signal from the *final* (extra-smoothed) MACD so
// the two lines stay internally consistent.
macd   = macdRaw * volFac
macd   := emaIf(macd, macdSmoothLen)
signal = ta.ema(macd, signalLength)
signal := emaIf(signal, sigSmoothLen)
hist   = macd - signal
hist   := emaIf(hist, histSmoothLen)

// ── MTF confirm series ───────────────────────────────────────────────────────────
macdHTF   = htfConfirm(macd)
signalHTF = htfConfirm(signal)

// ── Cross logic (aligned with HTF when set) ──────────────────────────────────────
bullCross = ta.crossover(macd, signal)  and (mtfTF == "" or macdHTF > signalHTF)
bearCross = ta.crossunder(macd, signal) and (mtfTF == "" or macdHTF < signalHTF)

// ── Divergence (pivot-based, optional) ───────────────────────────────────────────
left  = 5
right = 5
pl = ta.pivotlow(low, left, right)
ph = ta.pivothigh(high, left, right)
plCond = not na(pl)
phCond = not na(ph)

lastPL     = ta.valuewhen(plCond, pl, 0)
prevPL     = ta.valuewhen(plCond, pl, 1)
lastPLmacd = ta.valuewhen(plCond, macd[right], 0)
prevPLmacd = ta.valuewhen(plCond, macd[right], 1)
bullDiv = showDiv and plCond and lastPL < prevPL and lastPLmacd > prevPLmacd

lastPH     = ta.valuewhen(phCond, ph, 0)
prevPH     = ta.valuewhen(phCond, ph, 1)
lastPHmacd = ta.valuewhen(phCond, macd[right], 0)
prevPHmacd = ta.valuewhen(phCond, macd[right], 1)
bearDiv = showDiv and phCond and lastPH > prevPH and lastPHmacd < prevPHmacd

// ── Plots ────────────────────────────────────────────────────────────────────────
plot(macd,   "MACD",        color=color.new(color.purple, 0), linewidth=2)
plot(signal, "Signal Line", color=color.new(color.blue,   0), linewidth=2)

// 4-colour histogram: bright when momentum is expanding, faded when contracting
histRise = hist >= nz(hist[1])
colUp    = #26a69a
colDn    = #ef5350
histCol  = hist >= 0 ? (histRise ? colUp : color.new(colUp, 55)) : (histRise ? color.new(colDn, 55) : colDn)
plot(showHist ? hist : na, "Histogram", color=histCol, style=plot.style_columns)

plot(showCross and bullCross ? macd : na, "Cross Over",  style=plot.style_circles, color=color.new(color.green, 0), linewidth=3)
plot(showCross and bearCross ? macd : na, "Cross Under", style=plot.style_circles, color=color.new(color.red,   0), linewidth=3)
hline(0, "Zero Line", color=color.new(color.gray, 0))

plotshape(bullDiv, title="Bull Div", style=shape.triangleup,   location=location.belowbar, color=color.new(color.green, 0), size=size.tiny, text="DIV")
plotshape(bearDiv, title="Bear Div", style=shape.triangledown, location=location.abovebar, color=color.new(color.red,   0), size=size.tiny, text="DIV")

// ── Trend label (delivers the README's "Uptrend/Downtrend/Neutral" tag) ──────────
trendBull = macd > signal and macd > 0
trendBear = macd < signal and macd < 0
trendTxt  = trendBull ? "Uptrend" : trendBear ? "Downtrend" : "Neutral"
trendCol  = trendBull ? color.green : trendBear ? color.red : color.gray
mtfTxt    = mtfTF == "" ? "—" : (macdHTF > signalHTF ? "Bull" : macdHTF < signalHTF ? "Bear" : "Neutral")
mtfCol    = mtfTF == "" ? color.gray : (macdHTF > signalHTF ? color.green : macdHTF < signalHTF ? color.red : color.gray)

var table tbl = table.new(position.top_right, 2, 2, bgcolor=color.new(color.white, 88), frame_color=color.new(color.black, 75), frame_width=1)
if showLabel and barstate.islast
    table.cell(tbl, 0, 0, "MACD:", text_color=color.white, bgcolor=color.new(color.blue, 0))
    table.cell(tbl, 1, 0, trendTxt, text_color=trendCol, bgcolor=color.white)
    table.cell(tbl, 0, 1, "MTF:",  text_color=color.white, bgcolor=color.new(color.blue, 0))
    table.cell(tbl, 1, 1, mtfTxt,  text_color=mtfCol, bgcolor=color.white)

// ── Alerts (create via Alerts → Condition: GemHunter MACD+) ──────────────────────
alertcondition(bullCross, title="MACD+ ▲ Bullish Cross", message="GemHunter MACD+: bullish cross — {{ticker}} {{interval}}")
alertcondition(bearCross, title="MACD+ ▼ Bearish Cross", message="GemHunter MACD+: bearish cross — {{ticker}} {{interval}}")
alertcondition(bullDiv,   title="MACD+ • Bullish Divergence", message="GemHunter MACD+: bullish divergence — {{ticker}} {{interval}}")
alertcondition(bearDiv,   title="MACD+ • Bearish Divergence", message="GemHunter MACD+: bearish divergence — {{ticker}} {{interval}}")

Overview

MACD Integration for GemHunter (Smoothed) offers several moving average algorithms, including Ehlers SuperSmoother, DEMA, TEMA, RMA, and standard EMA, alongside an optional volume scaling factor to de-emphasize low-volume price moves. The script plots the MACD line, signal line, smoothed histogram, crossover dots, trend labels, and optional pivot-based divergences. Key inputs configure average types, smoothing lengths, volume caps, and higher-timeframe confirmation. Pivot-based divergences require confirmed swing points and appear with an inherent lag.

Details

Published by

Finland93 on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Divergence, Volume

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

pinescriptpinescript-indicatorstradingviewgemhunter

Settings

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

SettingTypeDefaultVariable
Sourcesourceclosesource
Fast Lengthint12fastLength
Slow Lengthint26slowLength
Signal Lengthint9signalLength
MA TypestringSuperSmoothermaType
Use Volume FactorbooltrueuseVolume
Volume SMA Lenint50volSmaLen
Volume EMA Lenint10volEmaLen
Volume Factor Cap (x)float1.8volCap
MTF Confirm TF (optional)timeframemtfTF
Show HistogrambooltrueshowHist
Show Cross DotsbooltrueshowCross
Show all 17 settings
SettingTypeDefaultVariable
Show Divergence (pivot-based)boolfalseshowDiv
Show Trend LabelbooltrueshowLabel
Extra MACD Smoothint3macdSmoothLen
Extra Signal Smoothint3sigSmoothLen
Extra Hist Smoothint2histSmoothLen
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

Oscillator Suite

by TamaraKGreen
46 stars

Oscillator Suite plots a normalised price oscillator in a separate pane and overlays a signal line that can use SMA, EMA, WMA, HMA, RMA, VWMA, T3, ZEMA, KAMA, or GKEMA. It marks bullish and bearish divergences, a smoothed money-flow series, confluence areas an

Indicator v5 Oscillators & momentumDivergence
Updated 7 weeks ago · None stated GitHub repository of Oscillator Suite

MFI Divergences

by tistaharahap
25 stars

This indicator plots the Money Flow Index in a separate pane and marks regular and hidden bullish and bearish divergences between price pivots and the oscillator. It builds the index from positive and negative money flow, then finds pivot highs and lows using

Indicator v4 Oscillators & momentumVolume
Updated 6 years ago · None stated GitHub repository of MFI Divergences
11 stars

This indicator plots a smoothed Z-score of cumulative volume delta in a separate pane, showing whether buying or selling pressure is dominant and when the reading enters extreme zones. It marks spot accumulation, climax or exhaustion, and pivot-based price-vol

Indicator v6 Oscillators & momentumVolume Repaints
Updated 7 weeks ago · MIT GitHub repository of CVD Z-Score [NeuNue]
9 stars

This indicator plots a heuristic volume-balance oscillator in a separate pane. It estimates signed volume from the close location inside each bar, multiplies that by volume, and sums the proxy over a rolling window. The sum is scaled between minus one and plus

Indicator v6 VolumeOscillators & momentum
Updated yesterday · MIT GitHub repository of CVD Bias [WavesUnchained]

DC-B v2.5

by crissrocca
9 stars

This indicator is an oscillator suite inspired by Market Cipher B and VuManChu Cipher B that plots in a separate pane. It combines a WaveTrend oscillator, a Money Flow Index (MFI) area, and an RSI indicator with automatic divergence detection. Visual signals h

Indicator v4 Oscillators & momentumDivergence
Updated 3 years ago · MPL-2.0 GitHub repository of DC-B v2.5

QPulse

by JasonTeixeira
9 stars

QPulse is a multi-factor indicator that draws in a separate pane to evaluate market momentum, volume flow, and volatility dynamics. It calculates volume delta, a cumulative delta proxy, advanced adaptive ATR, and a hybrid volume-weighted RSI with overbought an

Indicator v6 Oscillators & momentumVolatility & bands
Updated 12 days ago · Custom licence GitHub repository of QPulse

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