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)
- m = input(3,"Offset Multiple")
- w = input(4,"Histogram Width")
- number = input(true)
- 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
- c1 =correlation(d,nz(d[ 1]),len)
- c2 =correlation(d,nz(d[ 2]),len)
- c3 =correlation(d,nz(d[ 3]),len)
- 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)
- c31=correlation(d,nz(d[31]),len)
- c32=correlation(d,nz(d[32]),len)
- c33=correlation(d,nz(d[33]),len)
- c34=correlation(d,nz(d[34]),len)
- c35=correlation(d,nz(d[35]),len)
- c36=correlation(d,nz(d[36]),len)
- c37=correlation(d,nz(d[37]),len)
- c38=correlation(d,nz(d[38]),len)
- c39=correlation(d,nz(d[39]),len)
- c40=correlation(d,nz(d[40]),len)
- c41=correlation(d,nz(d[41]),len)
- c42=correlation(d,nz(d[42]),len)
- c43=correlation(d,nz(d[43]),len)
- c44=correlation(d,nz(d[44]),len)
- c45=correlation(d,nz(d[45]),len)
- c46=correlation(d,nz(d[46]),len)
- c47=correlation(d,nz(d[47]),len)
- c48=correlation(d,nz(d[48]),len)
- c49=correlation(d,nz(d[49]),len)
- c50=correlation(d,nz(d[50]),len)
- //critical value
- CV1 = 1.96/sqrt(len)
- CV2 = -(CV1)
- colorColumns = color.new(color.aqua,0)
- plot(c1 ,style=plot.style_histogram,offset=m*-50,show_last=1,title="lag 1" ,color=colorColumns,linewidth=w)
- plot(c2 ,style=plot.style_histogram,offset=m*-49,show_last=1,title="lag 2" ,color=colorColumns,linewidth=w)
- plot(c3 ,style=plot.style_histogram,offset=m*-48,show_last=1,title="lag 3" ,color=colorColumns,linewidth=w)
- plot(c4 ,style=plot.style_histogram,offset=m*-47,show_last=1,title="lag 4" ,color=colorColumns,linewidth=w)
- plot(c5 ,style=plot.style_histogram,offset=m*-46,show_last=1,title="lag 5" ,color=colorColumns,linewidth=w)
- plot(c6 ,style=plot.style_histogram,offset=m*-45,show_last=1,title="lag 6" ,color=colorColumns,linewidth=w)
- plot(c7 ,style=plot.style_histogram,offset=m*-44,show_last=1,title="lag 7" ,color=colorColumns,linewidth=w)
- plot(c8 ,style=plot.style_histogram,offset=m*-43,show_last=1,title="lag 8" ,color=colorColumns,linewidth=w)
- plot(c9 ,style=plot.style_histogram,offset=m*-42,show_last=1,title="lag 9" ,color=colorColumns,linewidth=w)
- plot(c10,style=plot.style_histogram,offset=m*-41,show_last=1,title="lag 10",color=colorColumns,linewidth=w)
- plot(c11,style=plot.style_histogram,offset=m*-40,show_last=1,title="lag 11",color=colorColumns,linewidth=w)
- plot(c12,style=plot.style_histogram,offset=m*-39,show_last=1,title="lag 12",color=colorColumns,linewidth=w)
- plot(c13,style=plot.style_histogram,offset=m*-38,show_last=1,title="lag 13",color=colorColumns,linewidth=w)
- plot(c14,style=plot.style_histogram,offset=m*-37,show_last=1,title="lag 14",color=colorColumns,linewidth=w)
- plot(c15,style=plot.style_histogram,offset=m*-36,show_last=1,title="lag 15",color=colorColumns,linewidth=w)
- plot(c16,style=plot.style_histogram,offset=m*-35,show_last=1,title="lag 16",color=colorColumns,linewidth=w)
- plot(c17,style=plot.style_histogram,offset=m*-34,show_last=1,title="lag 17",color=colorColumns,linewidth=w)
- plot(c18,style=plot.style_histogram,offset=m*-33,show_last=1,title="lag 18",color=colorColumns,linewidth=w)
- plot(c19,style=plot.style_histogram,offset=m*-32,show_last=1,title="lag 19",color=colorColumns,linewidth=w)
- plot(c20,style=plot.style_histogram,offset=m*-31,show_last=1,title="lag 20",color=colorColumns,linewidth=w)
- plot(c21,style=plot.style_histogram,offset=m*-30,show_last=1,title="lag 21",color=colorColumns,linewidth=w)
- plot(c22,style=plot.style_histogram,offset=m*-29,show_last=1,title="lag 22",color=colorColumns,linewidth=w)
- plot(c23,style=plot.style_histogram,offset=m*-28,show_last=1,title="lag 23",color=colorColumns,linewidth=w)
- plot(c24,style=plot.style_histogram,offset=m*-27,show_last=1,title="lag 24",color=colorColumns,linewidth=w)
- plot(c25,style=plot.style_histogram,offset=m*-26,show_last=1,title="lag 25",color=colorColumns,linewidth=w)
- plot(c26,style=plot.style_histogram,offset=m*-25,show_last=1,title="lag 26",color=colorColumns,linewidth=w)
- plot(c27,style=plot.style_histogram,offset=m*-24,show_last=1,title="lag 27",color=colorColumns,linewidth=w)
- plot(c28,style=plot.style_histogram,offset=m*-23,show_last=1,title="lag 28",color=colorColumns,linewidth=w)
- plot(c29,style=plot.style_histogram,offset=m*-22,show_last=1,title="lag 29",color=colorColumns,linewidth=w)
- plot(c30,style=plot.style_histogram,offset=m*-21,show_last=1,title="lag 30",color=colorColumns,linewidth=w)
- plot(c31,style=plot.style_histogram,offset=m*-20,show_last=1,title="lag 31",color=colorColumns,linewidth=w)
- plot(c32,style=plot.style_histogram,offset=m*-19,show_last=1,title="lag 32",color=colorColumns,linewidth=w)
- plot(c33,style=plot.style_histogram,offset=m*-18,show_last=1,title="lag 33",color=colorColumns,linewidth=w)
- plot(c34,style=plot.style_histogram,offset=m*-17,show_last=1,title="lag 34",color=colorColumns,linewidth=w)
- plot(c35,style=plot.style_histogram,offset=m*-16,show_last=1,title="lag 35",color=colorColumns,linewidth=w)
- plot(c36,style=plot.style_histogram,offset=m*-15,show_last=1,title="lag 36",color=colorColumns,linewidth=w)
- plot(c37,style=plot.style_histogram,offset=m*-14,show_last=1,title="lag 37",color=colorColumns,linewidth=w)
- plot(c38,style=plot.style_histogram,offset=m*-13,show_last=1,title="lag 38",color=colorColumns,linewidth=w)
- plot(c39,style=plot.style_histogram,offset=m*-12,show_last=1,title="lag 39",color=colorColumns,linewidth=w)
- plot(c40,style=plot.style_histogram,offset=m*-11,show_last=1,title="lag 40",color=colorColumns,linewidth=w)
- plot(c41,style=plot.style_histogram,offset=m*-10,show_last=1,title="lag 41",color=colorColumns,linewidth=w)
- plot(c42,style=plot.style_histogram,offset=m*-9 ,show_last=1,title="lag 42",color=colorColumns,linewidth=w)
- plot(c43,style=plot.style_histogram,offset=m*-8 ,show_last=1,title="lag 43",color=colorColumns,linewidth=w)
- plot(c44,style=plot.style_histogram,offset=m*-7 ,show_last=1,title="lag 44",color=colorColumns,linewidth=w)
- plot(c45,style=plot.style_histogram,offset=m*-6 ,show_last=1,title="lag 45",color=colorColumns,linewidth=w)
- plot(c46,style=plot.style_histogram,offset=m*-5 ,show_last=1,title="lag 46",color=colorColumns,linewidth=w)
- plot(c47,style=plot.style_histogram,offset=m*-4 ,show_last=1,title="lag 47",color=colorColumns,linewidth=w)
- plot(c48,style=plot.style_histogram,offset=m*-3 ,show_last=1,title="lag 48",color=colorColumns,linewidth=w)
- plot(c49,style=plot.style_histogram,offset=m*-2 ,show_last=1,title="lag 49",color=colorColumns,linewidth=w)
- plot(c50,style=plot.style_histogram,offset=m*-1 ,show_last=1,title="lag 50",color=colorColumns,linewidth=w)
- colorPlotShape = color.new(color.white,50)
- plotshape(number?c5 :na,text="0" ,textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-51)
- plotshape(number?c5 :na,text="5" ,textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-46)
- plotshape(number?c10:na,text="10",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-41)
- plotshape(number?c15:na,text="15",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-36)
- plotshape(number?c20:na,text="20",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-31)
- plotshape(number?c25:na,text="25",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-26)
- plotshape(number?c30:na,text="30",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-21)
- plotshape(number?c35:na,text="35",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-16)
- plotshape(number?c40:na,text="40",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-11)
- plotshape(number?c45:na,text="45",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-6)
- plotshape(number?c45:na,text="50",textcolor=colorPlotShape,style=shape.arrowdown,color=colorPlotShape,location=location.top,size=size.tiny,show_last=1,offset=m*-1)
- hline(0)
- hline(CV1)
- hline(CV2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement