SHARE
TWEET

laguerre tr

freeman03 Oct 21st, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=4
  2. //Original by DonovanWall: https://www.tradingview.com/script/JwaPW9af-Laguerre-Multi-Filter-DW/
  3. study("Laguerre True Range", shorttitle="LTR", overlay=true)
  4. src = input(defval=hl2, title="Source")
  5.  
  6. drawRibbon = input(false, "Draw Ribbon?")
  7. showcross = input(true, "Show cross over/under")
  8. //Gamma Inputs
  9. gamma1 = input(defval=0.1, step=0.001, title="Gamma 1")
  10. gamma2 = input(defval=0.15, step=0.001, title="Gamma 2")
  11. gamma3 = input(defval=0.2, step=0.001, title="Gamma 3")
  12. gamma4 = input(defval=0.25, step=0.001, title="Gamma 4")
  13. gamma5 = input(defval=0.3, step=0.001, title="Gamma 5")
  14. gamma6 = input(defval=0.35, step=0.001, title="Gamma 6")
  15. gamma7 = input(defval=0.4, step=0.001, title="Gamma 7")
  16. gamma8 = input(defval=0.45, step=0.001, title="Gamma 8")
  17. gamma9 = input(defval=0.5, step=0.001, title="Gamma 9")
  18. gamma10 = input(defval=0.55, step=0.001, title="Gamma 10")
  19. gamma11 = input(defval=0.6, step=0.001, title="Gamma 11")
  20. gamma12 = input(defval=0.65, step=0.001, title="Gamma 12")
  21. gamma13 = input(defval=0.7, step=0.001, title="Gamma 13")
  22. gamma14 = input(defval=0.75, step=0.001, title="Gamma 14")
  23. gamma15 = input(defval=0.8, step=0.001, title="Gamma 15")
  24. gamma16 = input(defval=0.85, step=0.001, title="Gamma 16")
  25. gamma17 = input(defval=0.9, step=0.001, title="Gamma 17")
  26. gamma18 = input(defval=0.95, step=0.001, title="Gamma 18")
  27.  
  28.  
  29. //Laguerre Filter
  30. laguerre(a, b) =>
  31.     l0 = 0.0
  32.     l1 = 0.0
  33.     l2 = 0.0
  34.     l3 = 0.0
  35.     l0 := (1 - b) * a + b * nz(l0[1])
  36.     l1 := -b * l0 + nz(l0[1]) + b * nz(l1[1])
  37.     l2 := -b * l1 + nz(l1[1]) + b * nz(l2[1])
  38.     l3 := -b * l2 + nz(l2[1]) + b * nz(l3[1])
  39.     laguerre = (l0 + 2 * l1 + 2 * l2 + l3) / 6
  40.     laguerre
  41.  
  42. //Filter Values
  43. lag1 = laguerre(src, gamma1)
  44. lag2 = laguerre(src, gamma2)
  45. lag3 = laguerre(src, gamma3)
  46. lag4 = laguerre(src, gamma4)
  47. lag5 = laguerre(src, gamma5)
  48. lag6 = laguerre(src, gamma6)
  49. lag7 = laguerre(src, gamma7)
  50. lag8 = laguerre(src, gamma8)
  51. lag9 = laguerre(src, gamma9)
  52. lag10 = laguerre(src, gamma10)
  53. lag11 = laguerre(src, gamma11)
  54. lag12 = laguerre(src, gamma12)
  55. lag13 = laguerre(src, gamma13)
  56. lag14 = laguerre(src, gamma14)
  57. lag15 = laguerre(src, gamma15)
  58. lag16 = laguerre(src, gamma16)
  59. lag17 = laguerre(src, gamma17)
  60. lag18 = laguerre(src, gamma18)
  61.  
  62. //Average Laguerre True Range
  63. altr = (laguerre(tr, gamma1) + laguerre(tr, gamma2) + laguerre(tr, gamma3) +
  64.    laguerre(tr, gamma4) + laguerre(tr, gamma5) + laguerre(tr, gamma6) +
  65.    laguerre(tr, gamma7) + laguerre(tr, gamma8) + laguerre(tr, gamma9) +
  66.    laguerre(tr, gamma10) + laguerre(tr, gamma11) + laguerre(tr, gamma12) +
  67.    laguerre(tr, gamma13) + laguerre(tr, gamma14) + laguerre(tr, gamma15) +
  68.    laguerre(tr, gamma16) + laguerre(tr, gamma17) + laguerre(tr, gamma18)) / 18
  69. amlag = (lag1 + lag2 + lag3 + lag4 + lag5 + lag6 + lag7 + lag8 + lag9 + lag10 + lag11 +
  70.    lag12 + lag13 + lag14 + lag15 + lag16 + lag17 + lag18) / 18
  71.  
  72. //Bands
  73. hb1 = amlag + altr * 1.618
  74. hb2 = amlag + 2 * altr * 1.618
  75. lb1 = amlag - altr * 1.618
  76. lb2 = amlag - 2 * altr * 1.618
  77.  
  78. fcolor = amlag >= amlag[1] ? color.lime : color.red
  79. bcolor = #651FFF
  80.  
  81. //Band Plots
  82. hplot2 = plot(hb2, color=bcolor, linewidth=2, title="High Band 2", transp=60)
  83. hplot1 = plot(hb1, color=bcolor, linewidth=2, title="High Band 1", transp=60)
  84. alplot = plot(amlag, color=bcolor, linewidth=1, title="Average Laguerre Filter", transp=80)
  85. lplot1 = plot(lb1, color=bcolor, linewidth=2, title="Low Band 1", transp=60)
  86. lplot2 = plot(lb2, color=bcolor, linewidth=2, title="Low Band 2", transp=60)
  87.  
  88. //Band Fills
  89. fill(hplot1, hplot2, color=bcolor, title="High Band Fill", transp=80)
  90. fill(lplot1, lplot2, color=bcolor, title="Low Band Fill", transp=80)
  91.  
  92. //Ribbon Plots
  93. plot(drawRibbon ? lag18 : na, color=lag18 >= lag18[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 18")
  94. plot(drawRibbon ? lag17 : na, color=lag17 >= lag17[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 17")
  95. plot(drawRibbon ? lag16 : na, color=lag16 >= lag16[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 16")
  96. plot(drawRibbon ? lag15 : na, color=lag15 >= lag15[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 15")
  97. plot(drawRibbon ? lag14 : na, color=lag14 >= lag14[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 14")
  98. plot(drawRibbon ? lag13 : na, color=lag13 >= lag13[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 13")
  99. plot(drawRibbon ? lag12 : na, color=lag12 >= lag12[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 12")
  100. plot(drawRibbon ? lag11 : na, color=lag11 >= lag11[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 11")
  101. plot(drawRibbon ? lag10 : na, color=lag10 >= lag10[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 10")
  102. plot(drawRibbon ? lag9 : na, color=lag9 >= lag9[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 9")
  103. plot(drawRibbon ? lag8 : na, color=lag8 >= lag8[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 8")
  104. plot(drawRibbon ? lag7 : na, color=lag7 >= lag7[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 7")
  105. plot(drawRibbon ? lag6 : na, color=lag6 >= lag6[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 6")
  106. plot(drawRibbon ? lag5 : na, color=lag5 >= lag5[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 5")
  107. plot(drawRibbon ? lag4 : na, color=lag4 >= lag4[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 4")
  108. plot(drawRibbon ? lag3 : na, color=lag3 >= lag3[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 3")
  109. plot(drawRibbon ? lag2 : na, color=lag2 >= lag2[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 2")
  110. plot(drawRibbon ? lag1 : na, color=lag1 >= lag1[1] ? color.lime : color.red, linewidth=1, title="Laguerre Filter 1")
  111.  
  112. crossdn = high < hb2[1] and high[1] >= hb2[1]  //and src < src[1]
  113. crossup = low > lb2[1] and low[1] <= lb2[1]  //and src > src[1]
  114. plotshape(showcross and crossdn ? hb2 : na, location=location.absolute, style=shape.labeldown, color=color.red, size=size.tiny, text="Sell", textcolor=color.white, transp=0, offset=-1)
  115. plotshape(showcross and crossup ? lb2 : na, location=location.absolute, style=shape.labelup, color=color.green, size=size.tiny, text="Buy", textcolor=color.white, transp=0, offset=-1)
  116.  
  117. barcolor(fcolor)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top