Indicator · Pine Script v4 · Own pane

MACD ReLoaded

by theonetrade· code credited to KivancOzbilgic

MACD ReLoaded is a momentum indicator that recalculates the traditional Moving Average Convergence Divergence using a user-selectable moving average type.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code295
Settings7inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

295 lines of Pine Script v4 from assets/indicator/bit-exact/macd_reloaded_PhtqdGBM.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

macd_reloaded_PhtqdGBM.pine
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © KivancOzbilgic


//developer: Gerald Appel
//author: @kivancozbilgic

study("MACD ReLoaded","MACDRe", overlay=false, resolution="")
src = input(close, title="Source")
length=input(12, "Short Moving Average Length", minval=1)
length1=input(26, "Long Moving Average Length", minval=1)
length2=input(9, "Trigger Length", minval=1)
T3a1 = input(0.7, "TILLSON T3 Volume Factor", step=0.1)
showhistogram = input(title="Show MACD Histogram?", type=input.bool, defval=true)

mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "DEMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF", "HULL", "TILL"])
Var_Func(src,length)=>
    valpha=2/(length+1)
    vud1=src>src[1] ? src-src[1] : 0
    vdd1=src<src[1] ? src[1]-src : 0
    vUD=sum(vud1,9)
    vDD=sum(vdd1,9)
    vCMO=nz((vUD-vDD)/(vUD+vDD))
    VAR=0.0
    VAR:=nz(valpha*abs(vCMO)*src)+(1-valpha*abs(vCMO))*nz(VAR[1])
VAR=Var_Func(src,length)
DEMA = ( 2 * ema(src,length)) - (ema(ema(src,length),length) )
Wwma_Func(src,length)=>
    wwalpha = 1/ length
    WWMA = 0.0
    WWMA := wwalpha*src + (1-wwalpha)*nz(WWMA[1])
WWMA=Wwma_Func(src,length)
Zlema_Func(src,length)=>
    zxLag = length/2==round(length/2) ? length/2 : (length - 1) / 2
    zxEMAData = (src + (src - src[zxLag]))
    ZLEMA = ema(zxEMAData, length)
ZLEMA=Zlema_Func(src,length)
Tsf_Func(src,length)=>
    lrc = linreg(src, length, 0)
    lrc1 = linreg(src,length,1)
    lrs = (lrc-lrc1)
    TSF = linreg(src, length, 0)+lrs
TSF=Tsf_Func(src,length)
HMA = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)))
T3e1=ema(src, length)
T3e2=ema(T3e1,length)
T3e3=ema(T3e2,length)
T3e4=ema(T3e3,length)
T3e5=ema(T3e4,length)
T3e6=ema(T3e5,length)
T3c1=-T3a1*T3a1*T3a1
T3c2=3*T3a1*T3a1+3*T3a1*T3a1*T3a1
T3c3=-6*T3a1*T3a1-3*T3a1-3*T3a1*T3a1*T3a1
T3c4=1+3*T3a1+T3a1*T3a1*T3a1+3*T3a1*T3a1
T3=T3c1*T3e6+T3c2*T3e5+T3c3*T3e4+T3c4*T3e3


getMA(src, length) =>
    ma = 0.0
    if mav == "SMA"
        ma := sma(src, length)
        ma

    if mav == "EMA"
        ma := ema(src, length)
        ma

    if mav == "WMA"
        ma := wma(src, length)
        ma

    if mav == "DEMA"
        ma := DEMA
        ma

    if mav == "TMA"
        ma := sma(sma(src, ceil(length / 2)), floor(length / 2) + 1)
        ma

    if mav == "VAR"
        ma := VAR
        ma

    if mav == "WWMA"
        ma := WWMA
        ma

    if mav == "ZLEMA"
        ma := ZLEMA
        ma

    if mav == "TSF"
        ma := TSF
        ma

    if mav == "HULL"
        ma := HMA
        ma

    if mav == "TILL"
        ma := T3
        ma
    ma
    
MA12=getMA(src, length)


Var_Func1(src,length1)=>
    valpha1=2/(length1+1)
    vud11=src>src[1] ? src-src[1] : 0
    vdd11=src<src[1] ? src[1]-src : 0
    vUD1=sum(vud11,9)
    vDD1=sum(vdd11,9)
    vCMO1=nz((vUD1-vDD1)/(vUD1+vDD1))
    VAR1=0.0
    VAR1:=nz(valpha1*abs(vCMO1)*src)+(1-valpha1*abs(vCMO1))*nz(VAR1[1])
VAR1=Var_Func1(src,length1)
DEMA1 = ( 2 * ema(src,length1)) - (ema(ema(src,length1),length1) )
Wwma_Func1(src,length1)=>
    wwalpha1 = 1/ length1
    WWMA1 = 0.0
    WWMA1 := wwalpha1*src + (1-wwalpha1)*nz(WWMA1[1])
WWMA1=Wwma_Func1(src,length1)
Zlema_Func1(src,length1)=>
    zxLag1 = length1/2==round(length1/2) ? length1/2 : (length1 - 1) / 2
    zxEMAData1 = (src + (src - src[zxLag1]))
    ZLEMA1 = ema(zxEMAData1, length1)
ZLEMA1=Zlema_Func1(src,length1)
Tsf_Func1(src,length1)=>
    lrc1 = linreg(src, length1, 0)
    lrc11 = linreg(src,length1,1)
    lrs1 = (lrc1-lrc11)
    TSF1 = linreg(src, length1, 0)+lrs1
TSF1=Tsf_Func1(src,length1)
HMA1 = wma(2 * wma(src, length1 / 2) - wma(src, length1), round(sqrt(length1)))
T3e11=ema(src, length1)
T3e21=ema(T3e11,length1)
T3e31=ema(T3e21,length1)
T3e41=ema(T3e31,length1)
T3e51=ema(T3e41,length1)
T3e61=ema(T3e51,length1)
T3c11=-T3a1*T3a1*T3a1
T3c21=3*T3a1*T3a1+3*T3a1*T3a1*T3a1
T3c31=-6*T3a1*T3a1-3*T3a1-3*T3a1*T3a1*T3a1
T3c41=1+3*T3a1+T3a1*T3a1*T3a1+3*T3a1*T3a1
T31=T3c11*T3e61+T3c21*T3e51+T3c31*T3e41+T3c41*T3e31


getMA1(src, length1) =>
    ma1 = 0.0
    if mav == "SMA"
        ma1 := sma(src, length1)
        ma1

    if mav == "EMA"
        ma1 := ema(src, length1)
        ma1

    if mav == "WMA"
        ma1 := wma(src, length1)
        ma1

    if mav == "DEMA"
        ma1 := DEMA1
        ma1

    if mav == "TMA"
        ma1 := sma(sma(src, ceil(length1 / 2)), floor(length1 / 2) + 1)
        ma1

    if mav == "VAR"
        ma1 := VAR1
        ma1

    if mav == "WWMA"
        ma1:= WWMA1
        ma1

    if mav == "ZLEMA"
        ma1 := ZLEMA1
        ma1

    if mav == "TSF"
        ma1 := TSF1
        ma1

    if mav == "HULL"
        ma1 := HMA1
        ma1

    if mav == "TILL"
        ma1 := T31
        ma1
    ma1
    
MA26=getMA1(src, length1)


src2=MA12-MA26

Var_Func2(src2,length2)=>
    valpha2=2/(length2+1)
    vud12=src2>src2[1] ? src2-src2[1] : 0
    vdd12=src2<src2[1] ? src2[1]-src2 : 0
    vUD2=sum(vud12,9)
    vDD2=sum(vdd12,9)
    vCMO2=nz((vUD2-vDD2)/(vUD2+vDD2))
    VAR2=0.0
    VAR2:=nz(valpha2*abs(vCMO2)*src2)+(1-valpha2*abs(vCMO2))*nz(VAR2[1])
VAR2=Var_Func2(src2,length2)
DEMA2 = ( 2 * ema(src2,length2)) - (ema(ema(src2,length2),length2) )
Wwma_Func2(src2,length2)=>
    wwalpha2 = 1/ length2
    WWMA2 = 0.0
    WWMA2 := wwalpha2*src2 + (1-wwalpha2)*nz(WWMA2[1])
WWMA2=Wwma_Func2(src2,length2)
Zlema_Func2(src2,length2)=>
    zxLag2 = length2/2==round(length2/2) ? length2/2 : (length2 - 1) / 2
    zxEMAData2 = (src2 + (src2 - src2[zxLag2]))
    ZLEMA2 = ema(zxEMAData2, length2)
ZLEMA2=Zlema_Func2(src2,length2)
Tsf_Func2(src2,length2)=>
    lrc2 = linreg(src2, length2, 0)
    lrc12 = linreg(src2,length2,1)
    lrs2 = (lrc2-lrc12)
    TSF2 = linreg(src2, length2, 0)+lrs2
TSF2=Tsf_Func2(src2,length2)
HMA2 = wma(2 * wma(src2, length2 / 2) - wma(src2, length2), round(sqrt(length2)))
T3e12=ema(src2, length2)
T3e22=ema(T3e12,length2)
T3e32=ema(T3e22,length2)
T3e42=ema(T3e32,length2)
T3e52=ema(T3e42,length2)
T3e62=ema(T3e52,length2)
T3c12=-T3a1*T3a1*T3a1
T3c22=3*T3a1*T3a1+3*T3a1*T3a1*T3a1
T3c32=-6*T3a1*T3a1-3*T3a1-3*T3a1*T3a1*T3a1
T3c42=1+3*T3a1+T3a1*T3a1*T3a1+3*T3a1*T3a1
T32=T3c12*T3e62+T3c22*T3e52+T3c32*T3e42+T3c42*T3e32


getMA2(src2, length2) =>
    ma2 = 0.0
    if mav == "SMA"
        ma2 := sma(src2, length2)
        ma2

    if mav == "EMA"
        ma2 := ema(src2, length2)
        ma2

    if mav == "WMA"
        ma2 := wma(src2, length2)
        ma2

    if mav == "DEMA"
        ma2 := DEMA2
        ma2

    if mav == "TMA"
        ma2 := sma(sma(src2, ceil(length2 / 2)), floor(length2 / 2) + 1)
        ma2

    if mav == "VAR"
        ma2 := VAR2
        ma2

    if mav == "WWMA"
        ma2 := WWMA2
        ma2

    if mav == "ZLEMA"
        ma2 := ZLEMA2
        ma2

    if mav == "TSF"
        ma2 := TSF2
        ma2

    if mav == "HULL"
        ma2 := HMA2
        ma2

    if mav == "TILL"
        ma2 := T32
        ma2
    ma2


MATR=getMA2(MA12-MA26, length2)
hist = src2 - MATR
plot(showhistogram ? hist : na, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? color.lime : #B2DFDB) : (hist[1] < hist ? #FFCDD2 : #EF5350) ))
plot(src2,title="MACDRe",color=#426BE6,linewidth=2)
plot(MATR,title="TRIGGER",color=#E60000,linewidth=2)

Overview

Traders can choose from 11 different smoothing algorithms, including SMA, EMA, WMA, DEMA, TMA, VAR, WWMA, ZLEMA, TSF, Hull MA, and Tillson T3. The script plots the resulting MACD line, trigger line, and an optional histogram in a separate indicator pane. Settings allow users to adjust short, long, and signal periods, source price, and the Tillson T3 volume factor.

Details

Published by

theonetrade on GitHub

Code credit

KivancOzbilgic, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

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-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Sourcesourceclosesrc
Short Moving Average Lengthint12length
Long Moving Average Lengthint26length1
Trigger Lengthint9length2
TILLSON T3 Volume Factorfloat0.7T3a1
Show MACD Histogram?booltrueshowhistogram
Moving Average TypestringVARmav
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

947 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 5 weeks ago · GPL-3.0 GitHub repository of Derivative Oscillator

Beep Boop

by magic8bot
408 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
368 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 3 months ago · None stated GitHub repository of MACD

[TVT] OBV with EMA

by namuan
321 stars

Calculates On-Balance Volume (OBV) alongside two Exponential Moving Averages (EMAs) applied directly to the cumulative OBV line. The indicator tracks volume flow relative to price movement and smooths it using short-term and longer-term EMAs to highlight volum

Indicator v6 VolumeOscillators & momentum
Updated 8 days ago · MIT GitHub repository of [TVT] OBV with EMA
228 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 4 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

MACD-V

by harryguiacorn
220 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

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers