• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Simple ACF abs(min-max) a guest Jan 26th, 2020 86 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) + nz(src)) +
14.    2 * (1 - alpha1) * nz(hp) - pow(1 - alpha1, 2) * nz(hp)
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)) / 2 + coeff2 * nz(filt1) + coeff3 * nz(filt1)
22.
23.
24.
25. d =  filt1-nz(filt1)
26.
27. //cc
28. c4 = correlation(d,nz(d),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),len)
35. c11=correlation(d,nz(d),len)
36. c12=correlation(d,nz(d),len)
37. c13=correlation(d,nz(d),len)
38. c14=correlation(d,nz(d),len)
39. c15=correlation(d,nz(d),len)
40. c16=correlation(d,nz(d),len)
41. c17=correlation(d,nz(d),len)
42. c18=correlation(d,nz(d),len)
43. c19=correlation(d,nz(d),len)
44. c20=correlation(d,nz(d),len)
45. c21=correlation(d,nz(d),len)
46. c22=correlation(d,nz(d),len)
47. c23=correlation(d,nz(d),len)
48. c24=correlation(d,nz(d),len)
49. c25=correlation(d,nz(d),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),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. Max = max(max(max(max(C4,C5,C6,C7,C8,C9,C10),C11,C12,C13,C14,C15,C16,C17,C18,C19),C20,C21,C22,C23,C24,C25),C29,C30)
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. P1 = 0.0
170.
171. if C5 == Max
172.     P1 := 5
173. if C6 == Max
174.     P1 := 6
175. if C7 == Max
176.     P1 := 7
177. if C8 == Max
178.     P1 := 8
179. if C9 == Max
180.     P1 := 9
181. if C10 == Max
182.     P1 := 10
183. if C11 == Max
184.     P1 := 11
185. if C12 == Max
186.     P1 := 12
187. if C13 == Max
188.     P1 := 13
189. if C14 == Max
190.     P1 := 14
191. if C15 == Max
192.     P1 := 15
193. if C16 == Max
194.     P1 := 16
195. if C17 == Max
196.     P1 := 17
197. if C18 == Max
198.     P1 := 18
199. if C19 == Max
200.     P1 := 19
201. if C20 == Max
202.     P1 := 20
203. if C21 == Max
204.     P1 := 21
205. if C22 == Max
206.     P1 := 22
207. if C23 == Max
208.     P1 := 23
209. if C24 == Max
210.     P1 := 24
211. if C25 == Max
212.     P1 := 25
213. if C26 == Max
214.     P1 := 26
215. if C27 == Max
216.     P1 := 27
217. if C28 == Max
218.     P1 := 28
219. if C29 == Max
220.     P1 := 29
221. if C30 == Max
222.     P1 := 30
223.
224. DC = abs(P-P1)*2
225.
226.
227.
228.
229. 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.
Top