Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Pig AutoCorrelation Function",precision=3)
- len=input(365,"Length")
- src=input(close)
- bgcolor(#000000c0)
- PI = 2 * asin(1)
- upper = input(48)
- lower = input(10)
- alpha1 = (cos(sqrt(2) * PI / upper) + sin(sqrt(2) * PI / upper) - 1) /
- cos(sqrt(2) * PI / upper)
- hp = 0.0
- hp := pow(1 - alpha1 / 2, 2) * (src - 2 * nz(src[1]) + nz(src[2])) +
- 2 * (1 - alpha1) * nz(hp[1]) - pow(1 - alpha1, 2) * nz(hp[2])
- a1 = exp(-PI * sqrt(2) / lower)
- coeff2 = 2 * a1 * cos(sqrt(2) * PI / lower)
- coeff3 = -pow(a1, 2)
- coeff1 = 1 - coeff2 - coeff3
- filt1 = 0.0
- filt1 := coeff1 * (hp + nz(hp[1])) / 2 + coeff2 * nz(filt1[1]) + coeff3 * nz(filt1[2])
- d = filt1-nz(filt1[1])
- //cc
- c4 = correlation(d,nz(d[4]),len)
- c5 =correlation(d,nz(d[ 5]),len)
- c6 =correlation(d,nz(d[ 6]),len)
- c7 =correlation(d,nz(d[ 7]),len)
- c8 =correlation(d,nz(d[ 8]),len)
- c9 =correlation(d,nz(d[ 9]),len)
- c10=correlation(d,nz(d[10]),len)
- c11=correlation(d,nz(d[11]),len)
- c12=correlation(d,nz(d[12]),len)
- c13=correlation(d,nz(d[13]),len)
- c14=correlation(d,nz(d[14]),len)
- c15=correlation(d,nz(d[15]),len)
- c16=correlation(d,nz(d[16]),len)
- c17=correlation(d,nz(d[17]),len)
- c18=correlation(d,nz(d[18]),len)
- c19=correlation(d,nz(d[19]),len)
- c20=correlation(d,nz(d[20]),len)
- c21=correlation(d,nz(d[21]),len)
- c22=correlation(d,nz(d[22]),len)
- c23=correlation(d,nz(d[23]),len)
- c24=correlation(d,nz(d[24]),len)
- c25=correlation(d,nz(d[25]),len)
- c26 =correlation(d,nz(d[ 26]),len)
- c27 =correlation(d,nz(d[ 27]),len)
- c28 =correlation(d,nz(d[ 28]),len)
- c29 =correlation(d,nz(d[ 29]),len)
- c30=correlation(d,nz(d[30]),len)
- C4 = c4
- C5 = c5
- C6 = c6
- C7 = c7
- C8 = c8
- C9 = c9
- C10 = c10
- C11 = c11
- C12= c12
- C13 = c13
- C14 = c14
- C15 = c15
- C16 = c16
- C17 = c17
- C18 = c18
- C19 = c19
- C20 = c20
- C21 = c21
- C22 = c22
- C23 = c23
- C24 = c24
- C25 = c25
- C26 = c26
- C27 = c27
- C28 = c28
- C29 = c29
- C30 = c30
- 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)
- P = 0.0
- if C5 == Min
- P := 5
- if C6 == Min
- P := 6
- if C7 == Min
- P := 7
- if C8 == Min
- P := 8
- if C9 == Min
- P := 9
- if C10 == Min
- P := 10
- if C11 == Min
- P := 11
- if C12 == Min
- P := 12
- if C13 == Min
- P := 13
- if C14 == Min
- P := 14
- if C15 == Min
- P := 15
- if C16 == Min
- P := 16
- if C17 == Min
- P := 17
- if C18 == Min
- P := 18
- if C19 == Min
- P := 19
- if C20 == Min
- P := 20
- if C21 == Min
- P := 21
- if C22 == Min
- P := 22
- if C23 == Min
- P := 23
- if C24 == Min
- P := 24
- if C25 == Min
- P := 25
- if C26 == Min
- P := 26
- if C27 == Min
- P := 27
- if C28 == Min
- P := 28
- if C29 == Min
- P := 29
- if C30 == Min
- P := 30
- DC =P*2
- plot(DC,color=color.green,transp=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement