• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Simple AP

a guest Jan 26th, 2020 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //@version=4
2. study("Pig Simple AutoCorrelation Periodogram",precision=2)
3. len=input(50,"Length")
4. src=input(close)
5. bgcolor(#000000c0)
6. PI = 2 * asin(1)
7. upper = input(48)
8. lower = input(10)
9. M = input(true,"Max and Min")
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. 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 C4 == Min
116.     P := 4
117. if C5 == Min
118.     P := 5
119. if C6 == Min
120.     P := 6
121. if C7 == Min
122.     P := 7
123. if C8 == Min
124.     P := 8
125. if C9 == Min
126.     P := 9
127. if C10 == Min
128.     P := 10
129. if C11 == Min
130.     P := 11
131. if C12 == Min
132.     P := 12
133. if C13 == Min
134.     P := 13
135. if C14 == Min
136.     P := 14
137. if C15 == Min
138.     P := 15
139. if C16 == Min
140.     P := 16
141. if C17 == Min
142.     P := 17
143. if C18 == Min
144.     P := 18
145. if C19 == Min
146.     P := 19
147. if C20 == Min
148.     P := 20
149. if C21 == Min
150.     P := 21
151. if C22 == Min
152.     P := 22
153. if C23 == Min
154.     P := 23
155. if C24 == Min
156.     P := 24
157. if C25 == Min
158.     P := 25
159. if C26 == Min
160.     P := 26
161. if C27 == Min
162.     P := 27
163. if C28 == Min
164.     P := 28
165. if C29 == Min
166.     P := 29
167. if C30 == Min
168.     P := 30
169.
170.
171. P1 = 0.0
172.
173. if C4 == Max
174.     P1 := 4
175. if C5 == Max
176.     P1 := 5
177. if C6 == Max
178.     P1 := 6
179. if C7 == Max
180.     P1 := 7
181. if C8 == Max
182.     P1 := 8
183. if C9 == Max
184.     P1 := 9
185. if C10 == Max
186.     P1 := 10
187. if C11 == Max
188.     P1 := 11
189. if C12 == Max
190.     P1 := 12
191. if C13 == Max
192.     P1 := 13
193. if C14 == Max
194.     P1 := 14
195. if C15 == Max
196.     P1 := 15
197. if C16 == Max
198.     P1 := 16
199. if C17 == Max
200.     P1 := 17
201. if C18 == Max
202.     P1 := 18
203. if C19 == Max
204.     P1 := 19
205. if C20 == Max
206.     P1 := 20
207. if C21 == Max
208.     P1 := 21
209. if C22 == Max
210.     P1 := 22
211. if C23 == Max
212.     P1 := 23
213. if C24 == Max
214.     P1 := 24
215. if C25 == Max
216.     P1 := 25
217. if C26 == Max
218.     P1 := 26
219. if C27 == Max
220.     P1 := 27
221. if C28 == Max
222.     P1 := 28
223. if C29 == Max
224.     P1 := 29
225. if C30 == Max
226.     P1 := 30
227.
228. DC = M? (abs(P-P1)+ P ) : 2*P
229.
230.
231.
232.
233. 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