MACDBB HistoX
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Auguraltrader

//@version=4
study(title="MACDBB HistoX")

fast_length = 5 
slow_length = 13 
src = ohlc4
signal_length = 13
sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)

// Calculation
fast_ma =  ema(src, fast_length)
slow_ma = ema(src, slow_length)
macd = fast_ma - slow_ma
signal = ema(macd, signal_length)
hist = macd - signal

//BB
length = input(11, minval=1)
mult = input(0.5, minval=0.001, maxval=50, title="StdDev")
basis = sma(macd, length)
dev = mult * stdev(macd, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)

// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = macd>upper? color.lime : macd<lower ? color.red : #0094ff
col_signal = color.orange //#ff6a00

plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=78 )
plot(macd, title="MACD", color=col_macd, transp=0)
plot(signal, title="Signal", color=col_signal, transp=0)


// Calculation MACDCCD
fast_ma2 =  ema(ohlc4, 13)
slow_ma2 = ema(ohlc4, 5)
macd2 = fast_ma2 - slow_ma2
signal2 = ema(macd2, 34)

fast_ma3 =  ema(ohlc4, 5)
slow_ma3 = ema(ohlc4, 13)
macd3 = fast_ma3 - slow_ma3
signal3 = ema(macd3, 34)

histX = signal3 - signal2
plot(histX, title="HistogramX", style=plot.style_columns, color=(histX>=0 ? (histX[1] < histX ? col_grow_above : col_fall_above) : (histX[1] < histX ? col_grow_below : col_fall_below) ), transp=88 )