Advertisement
JustUncleL

MA Ribbon R1

Mar 23rd, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. //@version=2
  2.  
  3. study(title="MA Ribbon R1 by JustUncleL", shorttitle="MA_RIBBON R1", overlay = true)
  4.  
  5. //
  6. // Revision: R1
  7. // Revision Author: JustUncleL
  8. //
  9. // Description:
  10. //
  11. // References:
  12. //
  13. // Modifications:
  14. // R1 - Original
  15. //
  16.  
  17. // Use Alternate Anchor TF for MAs
  18. anchor = input(0,minval=0,maxval=1440,title="Use Alternate Anchor TimeFrame (0=none, max=1440mins)")
  19.  
  20. // Fast MA - type, length
  21. type1 = input(defval="EMA", title="Fast MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
  22. len1 = input(defval=8, title="Fast - Length", minval=1)
  23. // Medium MA - type, length
  24. type2 = input(defval="EMA", title="Medium MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
  25. len2 = input(defval=21, title="Medium - Length", minval=2)
  26. //
  27. ma_src = input(close,title="Source")
  28. sBars = input(false,title="Show Coloured Bars")
  29. // - INPUTS END
  30.  
  31. // - FUNCTIONS
  32.  
  33. // Returns MA input selection variant, default to SMA if blank or typo.
  34. variant(type, src, len) =>
  35. v1 = sma(src, len) // Simple
  36. v2 = ema(src, len) // Exponential
  37. v3 = wma(src, len) // Weighted
  38. v4 = vwma(src, len) // Volume Weighted
  39. v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len // Smoothed
  40. v6 = 2 * v2 - ema(v2, len) // Double Exponential
  41. v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
  42. v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
  43. v11 = sma(sma(src,len),len) // Triangular
  44. // SuperSmoother filter
  45. // © 2013 John F. Ehlers
  46. a1 = exp(-1.414*3.14159 / len)
  47. b1 = 2*a1*cos(1.414*3.14159 / len)
  48. c2 = b1
  49. c3 = (-a1)*a1
  50. c1 = 1 - c2 - c3
  51. v9 = c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
  52. // Zero Lag Exponential
  53. ema1 = ema(src, len)
  54. ema2 = ema(ema1, len)
  55. v10 = ema1+(ema1-ema2)
  56. // return variant, defaults to SMA if input invalid.
  57. type=="EMA"?v2 : type=="WMA"?v3 : type=="VWMA"?v4 : type=="SMMA"?v5 : type=="DEMA"?v6 : type=="TEMA"?v7 : type=="HullMA"?v8 : type=="SSMA"?v9 : type=="ZEMA"?v10 : type=="TMA"? v11: v1
  58.  
  59. // - FUNCTIONS END
  60.  
  61. // Make sure we have minimum channel spread.
  62. Length2_ = (len2-len1)<1?len1+1:len2
  63.  
  64. // If this is 5min or less Time Frame select EMAs
  65. mult = not isintraday or anchor==0 or interval<=0 or interval>=anchor? 1 : round(anchor/interval)>1? round(anchor/interval) : 1
  66. Length1 = mult==1 ? len1 : (len1*mult)
  67. Length2 = mult==1 ? Length2_ : (Length2_*mult)
  68.  
  69.  
  70. // Get the two MAs
  71. ma1 = variant(type1,ma_src, Length1)
  72. ma2 = variant(type2,ma_src, Length2)
  73.  
  74. //Plot the Ribbon
  75. ma1_=plot( ma1,color=rising(ma1,2)?green:red,linewidth=2,transp=20,title="ma1")
  76. ma2_=plot( ma2,color=rising(ma2,2)?green:red,linewidth=2,transp=20,title="ma2")
  77. fcolor = ma1>ma2?green:red
  78. fill(ma1_,ma2_,color=fcolor,transp=80)
  79.  
  80. bc = not sBars? na : close>ma1 and close>ma2? green: close<ma1 and close<ma2? red : yellow
  81. barcolor(bc,title="Bar Colours")
  82.  
  83. //eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement