Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. //Created by user ChrisMoody updated 4-10-2014
  2. //Regular MACD Indicator with Histogram that plots 4 Colors Based on Direction Above and Below the Zero Line
  3. //Update allows Check Box Options, Show MacD & Signal Line, Show Change In color of MacD Line based on cross of Signal Line.
  4. //Show Dots at Cross of MacD and Signal Line, Histogram can show 4 colors or 1, Turn on and off Histogram.
  5. //Special Thanks to that incredible person in Tech Support whoem I won't say you r name so you don't get bombarded with emails
  6. //Note the feature Tech Support showed me on how to set the default timeframe of the indicator to the chart Timeframe, but also allow you to choose a different timeframe.
  7. //By the way I fully disclose that I completely STOLE the Dots at the MAcd Cross from "TheLark"
  8.  
  9. study(title="CM_MacD_Ult_MTF", shorttitle="CM_Ult_MacD_MTF")
  10. source = close
  11. useCurrentRes = input(true, title="Use Current Chart Resolution?")
  12. resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="60")
  13. smd = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
  14. sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
  15. sh = input(true, title="Show Histogram?")
  16. macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
  17. hist_colorChange = input(true,title="MacD Histogram 4 Colors?")
  18.  
  19. res = useCurrentRes ? period : resCustom
  20.  
  21. fastLength = input(12, minval=1), slowLength=input(26,minval=1)
  22. signalLength=input(9,minval=1)
  23.  
  24. fastMA = ema(source, fastLength)
  25. slowMA = ema(source, slowLength)
  26.  
  27. macd = fastMA - slowMA
  28. signal = sma(macd, signalLength)
  29. hist = macd - signal
  30.  
  31. outMacD = security(tickerid, res, macd)
  32. outSignal = security(tickerid, res, signal)
  33. outHist = security(tickerid, res, hist)
  34.  
  35. histA_IsUp = outHist > outHist[1] and outHist > 0
  36. histA_IsDown = outHist < outHist[1] and outHist > 0
  37. histB_IsDown = outHist < outHist[1] and outHist <= 0
  38. histB_IsUp = outHist > outHist[1] and outHist <= 0
  39.  
  40. //MacD Color Definitions
  41. macd_IsAbove = outMacD >= outSignal
  42. macd_IsBelow = outMacD < outSignal
  43.  
  44. plot_color = hist_colorChange ? histA_IsUp ? aqua : histA_IsDown ? blue : histB_IsDown ? red : histB_IsUp ? maroon :yellow :gray
  45. macd_color = macd_colorChange ? macd_IsAbove ? lime : red : red
  46. signal_color = macd_colorChange ? macd_IsAbove ? yellow : yellow : lime
  47.  
  48. circleYPosition = outSignal
  49.  
  50. plot(smd and outMacD ? outMacD : na, title="MACD", color=macd_color, linewidth=4)
  51. plot(smd and outSignal ? outSignal : na, title="Signal Line", color=signal_color, style=line ,linewidth=2)
  52. plot(sh and outHist ? outHist : na, title="Histogram", color=plot_color, style=histogram, linewidth=4)
  53. plot(sd and cross(outMacD, outSignal) ? circleYPosition : na, title="Cross", style=circles, linewidth=4, color=macd_color)
  54. hline(0, '0 Line', linestyle=solid, linewidth=2, color=white)
  55.  
  56.  
  57.  
  58. useCurrentRes1 = input(true, title="Use Current Chart Resolution?")
  59. resCustom1 = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="60")
  60. smd1 = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
  61. sd1 = input(true, title="Show Dots When MacD Crosses Signal Line?")
  62. sh1 = input(true, title="Show Histogram?")
  63. macd_colorChange1 = input(true,title="Change MacD Line Color-Signal Line Cross?")
  64. hist_colorChange1 = input(true,title="MacD Histogram 4 Colors?")
  65.  
  66. res1 = useCurrentRes1 ? period : resCustom1
  67.  
  68. fastLength1 = input(12, minval=1), slowLength1=input(26,minval=1)
  69. signalLength1=input(9,minval=1)
  70.  
  71. fastMA1 = ema(source, fastLength1)
  72. slowMA1 = ema(source, slowLength1)
  73.  
  74. macd1 = fastMA1 - slowMA1
  75. signal1 = sma(macd1, signalLength1)
  76. hist1 = macd1 - signal1
  77.  
  78. outMacD1 = security(tickerid, res1, macd1)
  79. outSignal1 = security(tickerid, res1, signal1)
  80. outHist1 = security(tickerid, res1, hist1)
  81.  
  82. histA_IsUp1 = outHist1 > outHist1[1] and outHist1 > 0
  83. histA_IsDown1 = outHist1 < outHist1[1] and outHist1 > 0
  84. histB_IsDown1 = outHist1 < outHist1[1] and outHist1 <= 0
  85. histB_IsUp1 = outHist1 > outHist1[1] and outHist1 <= 0
  86.  
  87. //MacD Color Definitions
  88. macd_IsAbove1 = outMacD1 >= outSignal1
  89. macd_IsBelow1 = outMacD1 < outSignal1
  90.  
  91. plot_color1 = hist_colorChange1 ? histA_IsUp1 ? aqua : histA_IsDown1 ? blue : histB_IsDown1 ? red : histB_IsUp1 ? maroon :yellow :gray
  92. macd_color1 = macd_colorChange1 ? macd_IsAbove1 ? lime : red : red
  93. signal_color1 = macd_colorChange1 ? macd_IsAbove1 ? yellow : yellow : lime
  94.  
  95. circleYPosition1 = outSignal1
  96.  
  97. plot(smd1 and outMacD1 ? outMacD1 : na, title="MACD", color=macd_color1, linewidth=4)
  98. plot(smd1 and outSignal1 ? outSignal1 : na, title="Signal Line", color=signal_color1, style=line ,linewidth=2)
  99. plot(sh1 and outHist1 ? outHist1 : na, title="Histogram", color=plot_color1, style=histogram, linewidth=4)
  100. plot(sd1 and cross(outMacD1, outSignal1) ? circleYPosition1 : na, title="Cross", style=circles, linewidth=4, color=macd_color1)
  101. hline(0, '0 Line', linestyle=solid, linewidth=2, color=white)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement