Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study(title="MACD", shorttitle="MACD v4", overlay=false)
- // Version 4.0
- source = close
- fastLength = input(12, minval=1), slowLength=input(26,minval=1)
- signalLength=input(9,minval=1)
- fastMA = ema(source, fastLength)
- slowMA = ema(source, slowLength)
- macd = fastMA - slowMA
- signal = sma(macd, signalLength)
- hist = macd - signal
- switch1=input(true, title="Enable Bar Color?")
- switch2=input(true, title="Enable Background Color?")
- plot(macd, color=#42cb00,linewidth=2)
- plot(signal, color=#ff1f1f,linewidth=2)
- // Histogram Color
- GetHistogramColor = 0
- GetHistogramColor := iff(hist > 0, 1, iff(hist < 0, -1, nz(GetHistogramColor[1], 0)))
- ColorHistogram = GetHistogramColor == -1 ? #ff1f1f: GetHistogramColor == 1 ? #42cb00 : #1976d2
- plot(hist, color=ColorHistogram, style=plot.style_histogram,linewidth=4)
- // Bar Color
- Trigger = input(0, title="Zeroline Trigger Value?")
- GetBarColor = 0
- GetBarColor := iff((macd > Trigger) and (hist > 0), 1, iff((macd < Trigger) and (hist < 0), -1, nz(GetBarColor[1], 0)))
- SelectBarColor = GetBarColor == -1 ? #ff1f1f: GetBarColor == 1 ? #42cb00: #1976d2
- barcolor(switch1?SelectBarColor:na)
- // Background Color
- GetBackgroundColor = 0
- GetBackgroundColor := iff((macd > Trigger) and (hist > 0), 1, iff((macd < Trigger) and (hist < 0), -1, nz(GetBackgroundColor[1], 0)))
- SelectBackgroundColor = GetBackgroundColor == -1 ? #ff1f1f: GetBackgroundColor == 1 ? #42cb00: #1976d2
- bgcolor(switch2?SelectBackgroundColor:na, transp=90)
- sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
- macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
- outMacD = macd
- outSignal = signal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement