Indicator · Pine Script v4 · Own pane

Doble MACD X

by theonetrade

Doble MACD X is a separate pane indicator combining two MACD calculations with market condition filters and divergence detection.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code125
Settings10inputs
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

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

double_macd_buy_and_sell_5cV2hGJk.pine
//@version=4
//
study(shorttitle="MACD_X", title="DOBLE MACD X", overlay=false)

vset= input(true, title="Ver Señal de Entrada de Tendencia")
vsct= input(false, title="Ver Señal de Contra Tendencia")
afa= input(true, title="Ver Zona Atlas")
afc= input(true, title="Ver Zona Choppiness")
chopi = input(50.0, title="Nivel Choppiness")
div_reg_al= input(true, title="Ver Divergencias Regulares Alcistas")
div_reg_ba= input(true, title="Ver Divergencias Regulares Bajistas")
div_ocu_al= input(false, title="Ver Divergencias Ocultas Alcistas")
div_ocu_ba= input(false, title="Ver Divergencias Ocultas Bajistas")
etiquetas= input(true, title="Ver Etiquetas De Divergencias")

negro=#000000
amarillo=#FFFF00
gris=#C0C0C0
rojo=#FF0000
blanco=#FFFFFF
verde_fuerte=#0AAC00

// LINEA 0
hline(0, color=negro, linestyle=hline.style_solid, editable=false)

// MACD 1
L1=12
L2=26
tp=close
m0 = ema(tp,L1)
m1 = ema(tp,L2)
macd_1 = (m0-m1) 
plot(macd_1, title='Macd 1226', color=gris, linewidth=2, style=plot.style_line, transp=0)
plot(macd_1, title='Macd 1226', color=gris, linewidth=2, style=plot.style_histogram, transp=0)

// MACD 2
L1A=5
L2A=15
tpa=close
m0a = ema(tpa,L1A)
m1a = ema(tpa,L2A)
macd_2 = (m0a-m1a) 
plot(macd_2, title='MacD 515', color=amarillo, linewidth=2, style=plot.style_line, transp=0)
plot(macd_2, title='MacD 515', color=amarillo, linewidth=2, style=plot.style_histogram, transp=0)

//Atlas Mini
length = 20
src = close
mult = 2.0
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
dbb = sqrt((upper-lower)/upper)*20
dbbmed = ema(dbb,120)
factor = dbbmed*4/5
atl = dbb-factor
all = atl>0?0:1
bgcolor(afa and all ? rojo : na,title='Zona Atlas', transp=90)

//Choppiness Index
length1 = 14
str = sum(tr,length1)
ltl = lowest(low <= close[1] ? low : close[1],length1)
hth = highest(high >= close[1] ? high : close[1],length1)
height = hth - ltl
chop = 100 * (log10(str / height) / log10(length1))
all1 = chop<chopi?0:1
bgcolor(afc and all1 ? rojo : na,title='Zona Choppiness', transp=90)

//Divergencias
max=highest(macd_2, 100)*1.5
nsc = max
nsv = max*-1

midpoint = (nsc + nsv) / 2
ploff = (nsc - midpoint) / 8

f_top_fractal(_src)=>_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
f_bot_fractal(_src)=>_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0

fractal_top1 = f_fractalize(macd_2) > 0 ? macd_2[2] : na
fractal_bot1 = f_fractalize(macd_2) < 0 ? macd_2[2] : na

high_prev1  = valuewhen(fractal_top1, macd_2[2], 0)[2]
high_price1 = valuewhen(fractal_top1, high[2], 0)[2]
low_prev1   = valuewhen(fractal_bot1, macd_2[2], 0)[2]
low_price1  = valuewhen(fractal_bot1, low[2], 0)[2]

regular_bearish_div1 = fractal_top1  and high[2] > high_price1 and macd_2[2] < high_prev1 and div_reg_ba == true
hidden_bearish_div1  = fractal_top1  and high[2] < high_price1 and macd_2[2] > high_prev1 and div_ocu_ba == true
regular_bullish_div1 = fractal_bot1  and low[2]  < low_price1  and macd_2[2] > low_prev1 and div_reg_al == true
hidden_bullish_div1  = fractal_bot1  and low[2]  > low_price1  and macd_2[2] < low_prev1 and div_ocu_al == true

col1 = regular_bearish_div1 ? rojo : hidden_bearish_div1 ? rojo : na
col2 = regular_bullish_div1 ? verde_fuerte : hidden_bullish_div1 ? verde_fuerte  : na

plot(title='Divergencias Bajistas', series = fractal_top1 ? macd_2[2] : na, color=col1, linewidth=1, offset=-2, transp=0)
plot(title='Divergencias Alcistas', series = fractal_bot1 ? macd_2[2] : na, color=col2, linewidth=1, offset=-2, transp=0)

plotshape(regular_bearish_div1 and div_reg_ba and etiquetas  ? macd_2[1] + ploff*0.5 : na, title="Divergencia Regular Bajista", text="🐻 R", location=location.absolute, style=shape.labeldown, size=size.tiny, color=rojo, textcolor=blanco,offset=-2, transp=0)
plotshape(hidden_bearish_div1 and div_ocu_ba and etiquetas  ? macd_2[1] + ploff*0.5 : na, title="Divergencia Oculta Bajista", text="🐻 O", location=location.absolute, style=shape.labeldown, size=size.tiny, color=rojo, textcolor=blanco,offset=-2, transp=0)

plotshape(regular_bullish_div1 and div_reg_al and etiquetas  ? macd_2[1] - ploff*0.5 : na, title="Divergencia Regular Alcista", text="🐂 R", location=location.absolute, style=shape.labelup, size=size.tiny, color=verde_fuerte, textcolor=blanco,offset=-2, transp=0)
plotshape(hidden_bullish_div1 and div_ocu_al and etiquetas  ? macd_2[1] - ploff*0.5 : na, title="Divergencia Oculta Alcista", text="🐂 O", location=location.absolute, style=shape.labelup, size=size.tiny, color=verde_fuerte, textcolor=blanco,offset=-2, transp=0)


//Estrategia

largo = crossover(macd_2,0) and macd_1 < macd_2 and macd_1[1] < macd_1[0] and macd_1 < 0 and vset
largo1 = crossover(macd_2,macd_1) and macd_2 < 0 and vsct
plotshape(largo  ? macd_2 - ploff*0.75 : na, title="Largo Entrada de Tendencia", location=location.absolute, style=shape.triangleup, size=size.tiny, color=verde_fuerte, transp=0)
plotshape(largo1  ? macd_2 - ploff*0.75 : na, title="Largo Entrada Contra Tendencia", location=location.absolute, style=shape.triangleup, size=size.tiny, color=verde_fuerte, transp=0)


corto = crossunder(macd_2,0) and macd_1 > macd_2 and macd_1[1] > macd_1[0] and macd_1 > 0 and vset
corto1 = crossunder(macd_2,macd_1) and macd_2 > 0 and vsct
plotshape(corto  ? macd_2 + ploff*0.75 : na, title="Corto Entrada de Tendencia", location=location.absolute, style=shape.triangledown, size=size.tiny, color=rojo, transp=0)
plotshape(corto1  ? macd_2 + ploff*0.75 : na, title="Corto Entrada Contra Tendencia", location=location.absolute, style=shape.triangledown, size=size.tiny, color=rojo, transp=0)

//Alertas
alertcondition(largo or largo1,title="Compras")
alertcondition(corto or corto1,title="Ventas")
alertcondition(largo or largo1 or corto or corto1,title="Compras/Ventas")

Overview

Doble MACD X plots fast (5/15) and standard (12/26) MACD lines with histograms to monitor momentum across multiple time horizons. Background shading highlights low volatility compression via the Atlas Mini algorithm and sideways consolidation via the Choppiness Index. The script also identifies regular and hidden bullish or bearish divergences on the faster MACD using fractal pivots.

Details

Published by

theonetrade on GitHub

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
Ver Señal de Entrada de Tendenciabooltruevset
Ver Señal de Contra Tendenciaboolfalsevsct
Ver Zona Atlasbooltrueafa
Ver Zona Choppinessbooltrueafc
Nivel Choppinessfloat50.0chopi
Ver Divergencias Regulares Alcistasbooltruediv_reg_al
Ver Divergencias Regulares Bajistasbooltruediv_reg_ba
Ver Divergencias Ocultas Alcistasboolfalsediv_ocu_al
Ver Divergencias Ocultas Bajistasboolfalsediv_ocu_ba
Ver Etiquetas De Divergenciasbooltrueetiquetas
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

Relative Strength Index

by deepentropy
13 stars

This indicator plots the Relative Strength Index in a separate pane from smoothed up and down price changes. It draws the RSI line with horizontal bands at 70, 50 and 30, plus overbought and oversold gradient fills. Optional settings add a smoothing moving ave

Indicator v6 Oscillators & momentumMoving averages
Updated 6 months ago · MIT GitHub repository of Relative Strength Index
2 stars

This indicator plots the relative strength index in a separate pane. It calculates RSI from the selected source and length with Wilder-style RMA smoothing, then draws the line against horizontal bands at 70, 50 and 30, with gradient fills in the overbought and

Indicator v6 Oscillators & momentumMoving averages
Updated 5 days ago · None stated GitHub repository of Relative strength index
2 stars

This indicator calculates the Relative Strength Index from a chosen price source and length and plots it in a separate pane. It draws horizontal bands at 70, 50, and 30 and fills the area between the outer bands. An optional moving average can smooth the RSI u

Indicator v6 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of Relative Strength Index
368 stars

This separate-pane indicator plots a MACD line, a signal line, and a histogram whose colors show whether the histogram is rising or falling above or below zero. The oscillator and signal can each use an SMA or an EMA, and an optional marker highlights MACD and

Indicator v5 Oscillators & momentumDivergence
Updated 3 months ago · None stated GitHub repository of MTF + MACD [Alorse]

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