TradingView
bas9in
Dec 7, 2021 7:37 PM

MACD Bar & BG Histo  

Dow Jones Industrial Average IndexTVC

Description

Original Source Code of trading view used

Bar color and background change added as per histogram for better trend change understand

Release Notes

Background Transparency Setting Change
Comments
inkka13
Hello, very good job !!!!! seriouly !!!!
Could you share your code ?
Too bad we can't use it with Tradingview alerts. Could you adapt it to have alerts to take position when the candle enters in colored histogram area?
bas9in
@inkka13,

//bar color and back groung color added for better trend change view,
//no change done in original code source devloped by tradingview

//@version=5
indicator(title="MACD Bar & BG Histo ", shorttitle="MACD Histo Bar & BG ", timeframe="", timeframe_gaps=true, overlay=true)
// Getting inputs
fast_length = input(title="Fast Length", defval=12)
slow_length = input(title="Slow Length", defval=26)
src = input(title="Source", defval=close)
signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA", "VWMA", "WMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA", "VWMA", "WMA"])
// 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 = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
//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)))
barcolor(color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
//plot(macd, title="MACD", color=col_macd)
//plot(signal, title="Signal", color=col_signal)

col_grow_above1 = input(#26A69A, "Above   Grow")
col_fall_above1 = input(#B2DFDB, "Fall")
col_grow_below1 = input(#FFCDD2, "Below Grow")
col_fall_below1 = input(#FF5252, "Fall")
bgcolor(transp=70, color=(hist>=0 ? (hist[1] < hist ? col_grow_above1 : col_fall_above1) : (hist[1] < hist ? col_grow_below1 : col_fall_below1)))
inkka13
@bas9in, My friend it seems there is an error on line 11...
Traitement du script...
line 11: Syntax error at input '('.

sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=)
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=)
bas9in
@inkka13,
input.string(title="Oscillator MA Type", defval="EMA", options = ["SMA", "EMA", "VWMA", "WMA"])
input.string(title="Signal Line MA Type", defval="EMA", options = ["SMA", "EMA", "VWMA", "WMA"])
More