MACD HIstgramMA signl Crossing
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// jfx_1503

//@version=5
indicator("MACD")

// 値の取得
fast_length=input.int(12,"Fast Length")
slow_length=input.int(26,"Slow Length")
src=input.source(close,"Source")
signal_length=input.int(10,"Fast Length",maxval=50,minval=1,step=9)

sma_source=input.bool(false,"Simple MA(Oscillator)")
sma_signal=input.bool(false,"Simple MA(Signal Line)")

// プロットの色
col_grow_above=#cfcfcf
col_grow_below=#cfcfcf
col_fall_above=#cfcfcf
col_fall_below=#cfcfcf
col_macd=#339207
col_signal=#ff0000
col_histma=#0011ff
col_crossAbove=#001affd3
col_crossBelow=#ff7038

// 計算
fast_ma=sma_source?ta.sma(src,fast_length):ta.ema(src,fast_length)
slow_ma=sma_source?ta.sma(src,slow_length):ta.ema(src,slow_length)

macd=fast_ma-slow_ma
signal=sma_signal?ta.sma(macd,signal_length):ta.ema(macd,signal_length)
hist=macd-signal
plot(hist,title="Histogram",style=plot.style_columns,color=color.new(hist>=0?(hist[1]<hist?col_grow_above:col_fall_above):(hist[1]<hist?col_grow_below:col_fall_below),transp=0))
plot(macd,title="MACD",color=color.new(col_macd,transp=0))
plot(signal,title="Signal",color=color.new(col_signal,transp=0))

histMaLength=input(5,"Histgram MA")
histMA=ta.sma(hist,histMaLength)

crossAbove = ta.crossover(histMA, signal)
crossBelow = ta.crossunder(histMA, signal)

plot(histMA,title="Histgram MA" ,color=color.new(col_histma,transp=0))

plotshape(series = crossAbove, title = "Cross Above", style = shape.triangledown, location=location.top,  color=color.new(col_crossAbove,transp=0), size="small")
plotshape(series = crossBelow, title = "Cross Below", style = shape.triangleup,location=location.bottom, color=color.new(col_crossBelow,transp=0), size="small")
