Advertisement
PineCoders

MACD v4

Oct 23rd, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. //@version=4
  2. study(title="MACD", shorttitle="MACD v4", overlay=false)
  3.  
  4. // Version 4.0
  5.  
  6. source = close
  7. fastLength = input(12, minval=1), slowLength=input(26,minval=1)
  8. signalLength=input(9,minval=1)
  9. fastMA = ema(source, fastLength)
  10. slowMA = ema(source, slowLength)
  11. macd = fastMA - slowMA
  12. signal = sma(macd, signalLength)
  13. hist = macd - signal
  14.  
  15. switch1=input(true, title="Enable Bar Color?")
  16. switch2=input(true, title="Enable Background Color?")
  17.  
  18. plot(macd, color=#42cb00,linewidth=2)
  19. plot(signal, color=#ff1f1f,linewidth=2)
  20.  
  21. // Histogram Color
  22. GetHistogramColor = 0
  23. GetHistogramColor := iff(hist > 0, 1, iff(hist < 0, -1, nz(GetHistogramColor[1], 0)))
  24. ColorHistogram = GetHistogramColor == -1 ? #ff1f1f: GetHistogramColor == 1 ? #42cb00 : #1976d2
  25. plot(hist, color=ColorHistogram, style=plot.style_histogram,linewidth=4)
  26.  
  27. // Bar Color
  28. Trigger = input(0, title="Zeroline Trigger Value?")
  29. GetBarColor = 0
  30. GetBarColor := iff((macd > Trigger) and (hist > 0), 1, iff((macd < Trigger) and (hist < 0), -1, nz(GetBarColor[1], 0)))
  31. SelectBarColor = GetBarColor == -1 ? #ff1f1f: GetBarColor == 1 ? #42cb00: #1976d2
  32. barcolor(switch1?SelectBarColor:na)
  33.  
  34. // Background Color
  35. GetBackgroundColor = 0
  36. GetBackgroundColor := iff((macd > Trigger) and (hist > 0), 1, iff((macd < Trigger) and (hist < 0), -1, nz(GetBackgroundColor[1], 0)))
  37. SelectBackgroundColor = GetBackgroundColor == -1 ? #ff1f1f: GetBackgroundColor == 1 ? #42cb00: #1976d2
  38. bgcolor(switch2?SelectBackgroundColor:na, transp=90)
  39.  
  40. sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
  41. macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
  42.  
  43. outMacD = macd
  44. outSignal = signal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement