Advertisement
Guest User

MAs

a guest
Oct 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. //@version=3
  2. study(title="[V] Multi MAs", shorttitle="[V] Multi MAs", overlay=true)
  3.  
  4. // Config
  5. src = input(close, title="Source")
  6. show_sma = input(title="Show SMAs", type=bool, defval=true)
  7. show_ema = input(title="Show EMAs", type=bool, defval=false)
  8. show_lr = input(title="Show L.Regressions", type=bool, defval=false)
  9. show_flat = input(title="Show Flatness", type=bool, defval=false)
  10.  
  11. // Inputs:
  12. input_sma1 = input(20, minval=1, title="SMA 1")
  13. input_sma2 = input(50, minval=1, title="SMA 2")
  14. input_sma3 = input(100, minval=1, title="SMA 3")
  15. input_sma4 = input(200, minval=1, title="SMA 4")
  16. input_sma5 = input(350, minval=1, title="SMA 5")
  17.  
  18. input_ema1 = input(2, minval=1, title="EMA 1")
  19. input_ema2 = input(21, minval=1, title="EMA 2")
  20. input_ema3 = input(55, minval=1, title="EMA 3")
  21. input_ema4 = input(100, minval=1, title="EMA 4")
  22. input_ema5 = input(200, minval=1, title="EMA 5")
  23.  
  24. input_lr1 = input(9, minval=1, title="L.Reg 1")
  25. input_lr2 = input(20, minval=1, title="L.Reg 2")
  26. input_lr3 = input(50, minval=1, title="L.Reg 3")
  27. input_lr4 = input(100, minval=1, title="L.Reg 4")
  28. input_lr5 = input(200, minval=1, title="L.Reg 5")
  29.  
  30. // Indicators
  31. ema1 = ema(src, input_ema1)
  32. ema2 = ema(src, input_ema2)
  33. ema3 = ema(src, input_ema3)
  34. ema4 = ema(src, input_ema4)
  35. ema5 = ema(src, input_ema5)
  36.  
  37. sma1 = sma(src, input_sma1)
  38. sma2 = sma(src, input_sma2)
  39. sma3 = sma(src, input_sma3)
  40. sma4 = sma(src, input_sma4)
  41. sma5 = sma(src, input_sma5)
  42.  
  43. lr1 = linreg(src, input_lr1, 0)
  44. lr2 = linreg(src, input_lr2, 0)
  45. lr3 = linreg(src, input_lr3, 0)
  46. lr4 = linreg(src, input_lr4, 0)
  47. lr5 = linreg(src, input_lr5, 0)
  48.  
  49. k1 = 0.001
  50. // flat = (sma2[1] - sma2) >= -(sma2*k1) and (sma2[1] - sma2) <= (sma2*k1)
  51. // down = (sma2[2] <= sma2[1] and sma2[1] > sma2)
  52. // up = (sma2[2] >= sma2[1] and sma2[1] < sma2)
  53. // sma4_state = (sma4[2] <= sma4[1] and sma4[1] > sma4) ? "down" : (sma4[1] - sma4) >= -(sma4*k1) and (sma4[1] - sma4) <= (sma4*k1) ? "flat" : (sma4[2] >= sma4[1] and sma4[1] < sma4) ? "up" : na
  54.  
  55. sma2_flat = (sma2[1] - sma2) >= -(sma2*k1) and (sma2[1] - sma2) <= (sma2*k1)
  56. sma2_down = (sma2[2] <= sma2[1] and sma2[1] > sma2)
  57. sma2_up = (sma2[2] >= sma2[1] and sma2[1] < sma2)
  58. sma4_flat = (sma4[1] - sma4) >= -(sma4*k1) and (sma4[1] - sma4) <= (sma4*k1)
  59. sma4_down = (sma4[2] <= sma4[1] and sma4[1] > sma4)
  60. sma4_up = (sma4[2] >= sma4[1] and sma4[1] < sma4)
  61.  
  62. ema5_flat = (ema5[1] - ema5) >= -(ema5*k1) and (ema5[1] - ema5) <= (ema5*k1)
  63. ema5_down = (ema5[2] <= ema5[1] and ema5[1] > ema5)
  64. ema5_up = (ema5[2] >= ema5[1] and ema5[1] < ema5)
  65. // flat ? plotarrow(codiff, colorup=teal, colordown=orange, transp=40)
  66. lr3_flat = (lr3[1] - lr3) >= -(lr3*k1) and (lr3[1] - lr3) <= (lr3*k1)
  67. lr3_down = (lr3[2] <= lr3[1] and lr3[1] > lr3)
  68. lr3_up = (lr3[2] >= lr3[1] and lr3[1] < lr3)
  69.  
  70. //// Plot
  71. plot(show_sma ? sma1 : na, title="SMA 1", color=orange, linewidth=1 )
  72. plot(show_sma ? sma2 : na, title="SMA 2", color=orange, linewidth=1 )
  73. plot(show_sma ? sma3 : na, title="SMA 3", color=orange, linewidth=2 )
  74. plot(show_sma ? sma4 : na, title="SMA 4", color=orange, linewidth=3 )
  75. plot(show_sma ? sma5 : na, title="SMA 5", color=orange, linewidth=3 )
  76.  
  77. plot(show_ema ? ema1 : na, title="EMA 1", color=#6CA7E2, linewidth=1 )
  78. plot(show_ema ? ema2 : na, title="EMA 2", color=#1976D2, linewidth=1 )
  79. plot(show_ema ? ema3 : na, title="EMA 3", color=#104C86, linewidth=2 )
  80. plot(show_ema ? ema4 : na, title="EMA 4", color=#104C86, linewidth=2 )
  81. plot(show_ema ? ema5 : na, title="EMA 5", color=#104C86, linewidth=3 )
  82.  
  83. plot(show_lr ? lr1 : na, title="L.Reg 1", color=red, linewidth=1)
  84. plot(show_lr ? lr2 : na, title="L.Reg 2", color=red, linewidth=1)
  85. plot(show_lr ? lr3 : na, title="L.Reg 3", color=red, linewidth=2)
  86. plot(show_lr ? lr4 : na, title="L.Reg 4", color=red, linewidth=2)
  87. plot(show_lr ? lr5 : na, title="L.Reg 5", color=red, linewidth=3)
  88.  
  89. plotshape( show_flat and show_sma and sma2_flat ? sma2 : na, style=shape.square, location=location.absolute, color=orange)
  90. plotshape( show_flat and show_sma and sma2_up? sma2 : na, style=shape.triangleup, location=location.absolute, color=green)
  91. plotshape( show_flat and show_sma and sma2_down? sma2 : na, style=shape.triangledown, location=location.absolute, color=red)
  92.  
  93. plotshape( show_flat and show_sma and sma4_flat and not sma4_down and not sma4_up ? sma4 : na, style=shape.square, location=location.absolute, color=orange)
  94. plotshape( show_flat and show_sma and sma4_down ? sma4 : na, style=shape.triangledown, location=location.absolute, color=red)
  95. plotshape( show_flat and show_sma and sma4_up ? sma4 : na, style=shape.triangleup, location=location.absolute, color=green)
  96.  
  97. // plotshape( show_flat and show_ema and ema5_flat and not ema5_down and not ema5_up ? ema5 : na, style=shape.square, location=location.absolute, color=blue)
  98. // plotshape( show_flat and show_ema and ema5_down ? ema5 : na, style=shape.triangledown, location=location.absolute, color=red)
  99. // plotshape( show_flat and show_ema and ema5_up ? ema5 : na, style=shape.triangleup, location=location.absolute, color=green)
  100.  
  101. plotshape( show_flat and show_lr and lr3_flat? lr3 : na, style=shape.square, location=location.absolute, color=orange)
  102. plotshape( show_flat and show_lr and lr3_down ? lr3 : na, style=shape.triangledown, location=location.absolute, color=red)
  103. plotshape( show_flat and show_lr and lr3_up ? lr3 : na, style=shape.triangleup, location=location.absolute, color=green)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement