SHARE
TWEET

ACF 2*min

a guest Jan 26th, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=4
  2. study("Pig AutoCorrelation Function",precision=3)
  3. len=input(365,"Length")
  4. src=input(close)
  5. bgcolor(#000000c0)
  6.  
  7. PI = 2 * asin(1)
  8. upper = input(48)
  9. lower = input(10)
  10. alpha1 = (cos(sqrt(2) * PI / upper) + sin(sqrt(2) * PI / upper) - 1) /
  11.    cos(sqrt(2) * PI / upper)
  12. hp = 0.0
  13. hp := pow(1 - alpha1 / 2, 2) * (src - 2 * nz(src[1]) + nz(src[2])) +
  14.    2 * (1 - alpha1) * nz(hp[1]) - pow(1 - alpha1, 2) * nz(hp[2])
  15.  
  16. a1 = exp(-PI * sqrt(2) / lower)
  17. coeff2 = 2 * a1 * cos(sqrt(2) * PI / lower)
  18. coeff3 = -pow(a1, 2)
  19. coeff1 = 1 - coeff2 - coeff3
  20. filt1 = 0.0
  21. filt1 := coeff1 * (hp + nz(hp[1])) / 2 + coeff2 * nz(filt1[1]) + coeff3 * nz(filt1[2])
  22.  
  23.  
  24.  
  25. d =  filt1-nz(filt1[1])
  26.  
  27. //cc
  28. c4 = correlation(d,nz(d[4]),len)
  29. c5 =correlation(d,nz(d[ 5]),len)
  30. c6 =correlation(d,nz(d[ 6]),len)
  31. c7 =correlation(d,nz(d[ 7]),len)
  32. c8 =correlation(d,nz(d[ 8]),len)
  33. c9 =correlation(d,nz(d[ 9]),len)
  34. c10=correlation(d,nz(d[10]),len)
  35. c11=correlation(d,nz(d[11]),len)
  36. c12=correlation(d,nz(d[12]),len)
  37. c13=correlation(d,nz(d[13]),len)
  38. c14=correlation(d,nz(d[14]),len)
  39. c15=correlation(d,nz(d[15]),len)
  40. c16=correlation(d,nz(d[16]),len)
  41. c17=correlation(d,nz(d[17]),len)
  42. c18=correlation(d,nz(d[18]),len)
  43. c19=correlation(d,nz(d[19]),len)
  44. c20=correlation(d,nz(d[20]),len)
  45. c21=correlation(d,nz(d[21]),len)
  46. c22=correlation(d,nz(d[22]),len)
  47. c23=correlation(d,nz(d[23]),len)
  48. c24=correlation(d,nz(d[24]),len)
  49. c25=correlation(d,nz(d[25]),len)
  50. c26 =correlation(d,nz(d[ 26]),len)
  51. c27 =correlation(d,nz(d[ 27]),len)
  52. c28 =correlation(d,nz(d[ 28]),len)
  53. c29 =correlation(d,nz(d[ 29]),len)
  54. c30=correlation(d,nz(d[30]),len)
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. C4 = c4
  65. C5 = c5
  66. C6 = c6
  67. C7 = c7
  68. C8 = c8
  69. C9 = c9
  70. C10 = c10
  71. C11 = c11
  72. C12= c12
  73. C13 = c13
  74. C14 = c14
  75. C15 = c15
  76. C16 = c16
  77. C17 = c17
  78. C18 = c18
  79. C19 = c19
  80. C20 = c20
  81. C21 = c21
  82. C22 = c22
  83. C23 = c23
  84. C24 = c24
  85. C25 = c25
  86. C26 = c26
  87. C27 = c27
  88. C28 = c28
  89. C29 = c29
  90. C30 = c30
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. Min = min(min(min(min(C4,C5,C6,C7,C8,C9,C10),C11,C12,C13,C14,C15,C16,C17,C18,C19),C20,C21,C22,C23,C24,C25,C26,C27,C28),C29,C30)
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. P = 0.0
  114.  
  115. if C5 == Min
  116.     P := 5
  117. if C6 == Min
  118.     P := 6
  119. if C7 == Min
  120.     P := 7
  121. if C8 == Min
  122.     P := 8
  123. if C9 == Min
  124.     P := 9
  125. if C10 == Min
  126.     P := 10
  127. if C11 == Min
  128.     P := 11
  129. if C12 == Min
  130.     P := 12
  131. if C13 == Min
  132.     P := 13    
  133. if C14 == Min
  134.     P := 14    
  135. if C15 == Min
  136.     P := 15    
  137. if C16 == Min
  138.     P := 16    
  139. if C17 == Min
  140.     P := 17    
  141. if C18 == Min
  142.     P := 18    
  143. if C19 == Min
  144.     P := 19    
  145. if C20 == Min
  146.     P := 20
  147. if C21 == Min
  148.     P := 21
  149. if C22 == Min
  150.     P := 22
  151. if C23 == Min
  152.     P := 23    
  153. if C24 == Min
  154.     P := 24    
  155. if C25 == Min
  156.     P := 25    
  157. if C26 == Min
  158.     P := 26
  159. if C27 == Min
  160.     P := 27
  161. if C28 == Min
  162.     P := 28
  163. if C29 == Min
  164.     P := 29
  165. if C30 == Min
  166.     P := 30
  167.  
  168.  
  169.  
  170.  
  171. DC =P*2
  172.  
  173.    
  174.  
  175.    
  176. plot(DC,color=color.green,transp=0)
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