Moving Average Convergence Divergence and Momentum
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Teji_Singh

//@version=5
indicator(title="Moving Average Convergence Divergence and Momentum", shorttitle="MACD_MOM", timeframe="", timeframe_gaps=true)
//Use MACD line for Trend identifiaiton and Histogram for Momentum

// Getting inputs
fast_length = input(title="Fast Length", defval=20)
slow_length = input(title="Slow Length", defval=100)
src = input(title="Source", defval=close)
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 20)

// Plot colors
col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")

// Calculating
fast_ma = ta.ema(src, fast_length)
slow_ma = ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = ta.ema(macd, signal_length)
hist = macd - signal
Momentum = ta.sma(hist,signal_length)

//Rules
Buy = macd > 0 and hist > Momentum
Positive = macd > 0 and hist < Momentum
Sell = macd < 0 and hist < Momentum
Negative = macd < 0 and hist > Momentum

// Plot
plot(hist, title="Histogram", style=plot.style_columns, color=(Buy ? col_grow_above : Positive ? col_fall_above : Sell ? col_fall_below : Negative ? col_grow_below : na))
plot(macd, title="MACD", color=col_macd)
//plot(signal, title="Signal", color=col_signal)
plot(Momentum, title = "Hist Momentum", color = color.yellow)