Advertisement
PineCoders

MTF 4 KAMA

Jul 12th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. //@version=4
  2. study(title="Quadruple Kaufman Adaptive Moving Average", shorttitle="QKAMA4", overlay=true)
  3.  
  4. length1 = input(14, minval=1)
  5. fastMA1 = input(2, minval=1)
  6. slowMA1 = input(20, minval=1)
  7. src1 = input(title="Source 1", type=input.source, defval=close)
  8. tf1 = input(title="Resolution 1", type=input.resolution, defval = "")
  9. length2 = input(14, minval=1)
  10. fastMA2 = input(3, minval=1)
  11. slowMA2 = input(30, minval=1)
  12. tf2 = input(title="Resolution 2", type=input.resolution, defval = "")
  13. src2 = input(title="Source 2", type=input.source, defval=close)
  14. length3 = input(14, minval=1)
  15. fastMA3 = input(4, minval=1)
  16. slowMA3 = input(40, minval=1)
  17. src3 = input(title="Source 3", type=input.source, defval=close)
  18. tf3 = input(title="Resolution 3", type=input.resolution, defval = "")
  19. length4 = input(14, minval=1)
  20. fastMA4 = input(5, minval=1)
  21. slowMA4 = input(50, minval=1)
  22. src4 = input(title="Source 4", type=input.source, defval=close)
  23. tf4 = input(title="Resolution 4", type=input.resolution, defval = "")
  24.  
  25. volatility1 = sum(abs(src1-src1[1]), length1)
  26. volatility2 = sum(abs(src2-src2[1]), length2)
  27. volatility3 = sum(abs(src3-src3[1]), length3)
  28. volatility4 = sum(abs(src4-src4[1]), length4)
  29.  
  30. change1 = abs(src1-src1[length1-1])
  31. change2 = abs(src2-src2[length2-1])
  32. change3 = abs(src3-src3[length3-1])
  33. change4 = abs(src4-src4[length4-1])
  34.  
  35. er1 = iff(volatility1 != 0, change1/volatility1, 0)
  36. er2 = iff(volatility2 != 0, change2/volatility2, 0)
  37. er3 = iff(volatility3 != 0, change3/volatility3, 0)
  38. er4 = iff(volatility4 != 0, change4/volatility4, 0)
  39.  
  40. fastSC1 = 2/(fastMA1+1)
  41. fastSC2 = 2/(fastMA2+1)
  42. fastSC3 = 2/(fastMA3+1)
  43. fastSC4 = 2/(fastMA4+1)
  44.  
  45. slowSC1 = 2/(slowMA1+1)
  46. slowSC2 = 2/(slowMA2+1)
  47. slowSC3 = 2/(slowMA3+1)
  48. slowSC4 = 2/(slowMA4+1)
  49.  
  50. sc1 = pow((er1*(fastSC1-slowSC1))+slowSC1, 2)
  51. sc2 = pow((er2*(fastSC2-slowSC2))+slowSC2, 2)
  52. sc3 = pow((er3*(fastSC3-slowSC3))+slowSC3, 2)
  53. sc4 = pow((er4*(fastSC4-slowSC4))+slowSC4, 2)
  54.  
  55. f_k(_sc) =>
  56. var _k = 0.
  57. _k := _k + _sc * (hl2-_k)
  58.  
  59. kamaR1 = security(syminfo.tickerid, tf1, f_k(sc1))
  60. kamaR2 = security(syminfo.tickerid, tf2, f_k(sc2))
  61. kamaR3 = security(syminfo.tickerid, tf3, f_k(sc3))
  62. kamaR4 = security(syminfo.tickerid, tf4, f_k(sc4))
  63.  
  64. plot(kamaR1, color=color.yellow, title="KAMA1")
  65. plot(kamaR2, color=#2cfffe, title="KAMA2")
  66. plot(kamaR3, color=color.fuchsia, title="KAMA3")
  67. plot(kamaR4, color=color.red, title="KAMA4")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement