Advertisement
CryptoAdvisor

kama 1.0

Jan 15th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © CryptoAdvisor_
  3.  
  4. //@version=2
  5. study("Kama CryptoAdvisor v1.0")
  6.  
  7. length = input(title="Length", type=integer, defval=18)
  8. fastLength = input(title="Fast EMA Length", type=integer, defval=2)
  9. slowLength = input(title="Slow EMA Length", type=integer, defval=30)
  10.  
  11. //LOW
  12. mom = abs(change(low, length))
  13. volatility = sum(abs(change(low)), length)
  14. // Efficiency Ratio
  15. er = volatility != 0 ? mom / volatility : 0
  16. fastAlpha = 2 / (fastLength + 1)
  17. slowAlpha = 2 / (slowLength + 1)
  18. // KAMA Alpha
  19. sc = pow((er * (fastAlpha - slowAlpha)) + slowAlpha, 2)
  20. kama = 0.0
  21. kama := sc * low + (1 - sc) * nz(kama[1])
  22.  
  23. //HIGH
  24. mom1 = abs(change(high, length))
  25. volatility1 = sum(abs(change(high)), length)
  26. // Efficiency Ratio
  27. er1 = volatility1 != 0 ? mom1 / volatility1 : 0
  28. // KAMA Alpha
  29. sc1 = pow((er1 * (fastAlpha - slowAlpha)) + slowAlpha, 2)
  30. kama1 = 0.0
  31. kama1 := sc1 * high + (1 - sc1) * nz(kama1[1])
  32.  
  33.  
  34.  
  35.  
  36.  
  37. //Price Bands
  38. show_P1 = input(true, type=bool, title="Show Kama with computed volatility(RMS)")
  39. periods = input(title="RMS Periods", type=integer, defval=60)
  40. t = input(title="Time for price bands", type=integer, defval=4)
  41. rms_h=pow(sum(pow(log(high/high[1]),2),periods)/periods,0.5)
  42. rms_l=pow(sum(pow(log(low /low[1]),2), periods)/periods,0.5)
  43.  
  44. plot(show_P1 ? (kama+kama1)/2 : na, color=gray, title="MidPoint", linewidth=3, transp=0)
  45. plot(show_P1 ? kama*exp(-rms_l*1*sqrt(t)) : na, color=gray, title="-1 dev.", linewidth=1, transp=0)
  46. plot(show_P1 ? kama1*exp(rms_h*1*sqrt(t)) : na, color=gray, title="+1 dev.", linewidth=1, transp=0)
  47. plot(show_P1 ? kama*exp(-rms_l*2*sqrt(t)) : na, color=gray, title="-2 dev.", linewidth=2, transp=0)
  48. plot(show_P1 ? kama1*exp(rms_h*2*sqrt(t)) : na, color=gray, title="+2 dev.", linewidth=2, transp=0)
  49.  
  50. show_P2 = input(false, type=bool, title="Show Kama with fixed volatility using DELTA parameter")
  51. delta = input(1.78,"Delta High",step=0.01)
  52. deltal= input(0.58,"Delta Low",step=0.01)
  53. plot(show_P2 ? (kama+kama1)/2 : na, color=gray, title="MidPoint", linewidth=2, transp=0)
  54. plot(show_P2 ? kama*deltal : na, color=gray, title="-1 dev.", linewidth=1, transp=0)
  55. plot(show_P2 ? kama1*delta : na, color=gray, title="+1 dev.", linewidth=1, transp=0)
  56. //plot(show_P2 ? kama*(deltal*2) : na, color=gray, title="-2 dev.", linewidth=2, transp=0)
  57. //plot(show_P2 ? kama1*(delta*2) : na, color=gray, title="+2 dev.", linewidth=2, transp=0)
  58.  
  59. //EFF RATIO
  60. show_SNR = input(false, type=bool, title="Show Kama Efficiency Ratio")
  61. SNR_Smoothing = input(5,"EMA periods smoothing SNR",step=1)
  62. plot(show_SNR ? ema(er,SNR_Smoothing) : na, color=red, title="SNR Ratio Low of the bar")
  63. plot(show_SNR ? ema(er1,SNR_Smoothing) : na, color=blue, title="SNR Ratio High of the bar")
  64. plot(show_SNR ? 0.30 : na, color=white, title="0.60 thresold", linewidth=1, transp=80)
  65. plot(show_SNR ? 0.00 : na, color=white, title="zeroline", linewidth=1, transp=80)
  66. plot(show_SNR ? 1.00 : na, color=white, title="upper limit", linewidth=1, transp=80)
  67.  
  68.  
  69. //Paint Bars
  70. showcolors1 = input(false, type=bool, title="Strong/Flat Market")
  71. strong_market = ema(er,SNR_Smoothing) > 0.80 or ema(er1,SNR_Smoothing) > 0.80 and showcolors1==true
  72. flat_market = ema(er1,SNR_Smoothing) < 0.30 or ema(er1,SNR_Smoothing) < 0.30 and showcolors1==true
  73. barcolor(showcolors1 and flat_market ? red : na)
  74. barcolor(showcolors1 and strong_market ? white : na)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement