Advertisement
Guest User

Roofing ACF

a guest
Jan 25th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. //@version=4
  2. study("Pig AutoCorrelation Function",precision=3)
  3. len=input(365,"Length")
  4. src = input(close)
  5. m = input(3,"Offset Multiple")
  6. w = input(4,"Histogram Width")
  7. number = input(true)
  8.  
  9.  
  10.  
  11. PI = 2 * asin(1)
  12. upper = input(48)
  13. lower = input(10)
  14. alpha1 = (cos(sqrt(2) * PI / upper) + sin(sqrt(2) * PI / upper) - 1) /
  15. cos(sqrt(2) * PI / upper)
  16. hp = 0.0
  17. hp := pow(1 - alpha1 / 2, 2) * (src - 2 * nz(src[1]) + nz(src[2])) +
  18. 2 * (1 - alpha1) * nz(hp[1]) - pow(1 - alpha1, 2) * nz(hp[2])
  19.  
  20. a1 = exp(-PI * sqrt(2) / lower)
  21. coeff2 = 2 * a1 * cos(sqrt(2) * PI / lower)
  22. coeff3 = -pow(a1, 2)
  23. coeff1 = 1 - coeff2 - coeff3
  24. filt1 = 0.0
  25. filt1 := coeff1 * (hp + nz(hp[1])) / 2 + coeff2 * nz(filt1[1]) + coeff3 * nz(filt1[2])
  26.  
  27.  
  28.  
  29. d = filt1-nz(filt1[1])
  30.  
  31.  
  32.  
  33. //cc
  34. c1 =correlation(d,nz(d[ 1]),len)
  35. c2 =correlation(d,nz(d[ 2]),len)
  36. c3 =correlation(d,nz(d[ 3]),len)
  37. c4 =correlation(d,nz(d[ 4]),len)
  38. c5 =correlation(d,nz(d[ 5]),len)
  39. c6 =correlation(d,nz(d[ 6]),len)
  40. c7 =correlation(d,nz(d[ 7]),len)
  41. c8 =correlation(d,nz(d[ 8]),len)
  42. c9 =correlation(d,nz(d[ 9]),len)
  43. c10=correlation(d,nz(d[10]),len)
  44. c11=correlation(d,nz(d[11]),len)
  45. c12=correlation(d,nz(d[12]),len)
  46. c13=correlation(d,nz(d[13]),len)
  47. c14=correlation(d,nz(d[14]),len)
  48. c15=correlation(d,nz(d[15]),len)
  49. c16=correlation(d,nz(d[16]),len)
  50. c17=correlation(d,nz(d[17]),len)
  51. c18=correlation(d,nz(d[18]),len)
  52. c19=correlation(d,nz(d[19]),len)
  53. c20=correlation(d,nz(d[20]),len)
  54. c21=correlation(d,nz(d[21]),len)
  55. c22=correlation(d,nz(d[22]),len)
  56. c23=correlation(d,nz(d[23]),len)
  57. c24=correlation(d,nz(d[24]),len)
  58. c25=correlation(d,nz(d[25]),len)
  59. c26=correlation(d,nz(d[26]),len)
  60. c27=correlation(d,nz(d[27]),len)
  61. c28=correlation(d,nz(d[28]),len)
  62. c29=correlation(d,nz(d[29]),len)
  63. c30=correlation(d,nz(d[30]),len)
  64. c31=correlation(d,nz(d[31]),len)
  65. c32=correlation(d,nz(d[32]),len)
  66. c33=correlation(d,nz(d[33]),len)
  67. c34=correlation(d,nz(d[34]),len)
  68. c35=correlation(d,nz(d[35]),len)
  69. c36=correlation(d,nz(d[36]),len)
  70. c37=correlation(d,nz(d[37]),len)
  71. c38=correlation(d,nz(d[38]),len)
  72. c39=correlation(d,nz(d[39]),len)
  73. c40=correlation(d,nz(d[40]),len)
  74. c41=correlation(d,nz(d[41]),len)
  75. c42=correlation(d,nz(d[42]),len)
  76. c43=correlation(d,nz(d[43]),len)
  77. c44=correlation(d,nz(d[44]),len)
  78. c45=correlation(d,nz(d[45]),len)
  79. c46=correlation(d,nz(d[46]),len)
  80. c47=correlation(d,nz(d[47]),len)
  81. c48=correlation(d,nz(d[48]),len)
  82. c49=correlation(d,nz(d[49]),len)
  83. c50=correlation(d,nz(d[50]),len)
  84.  
  85. //critical value
  86. CV1 = 1.96/sqrt(len)
  87. CV2 = -(CV1)
  88.  
  89. colorColumns = color.new(color.aqua,0)
  90. plot(c1 ,style=plot.style_histogram,offset=m*-50,show_last=1,title="lag 1" ,color=colorColumns,linewidth=w)
  91. plot(c2 ,style=plot.style_histogram,offset=m*-49,show_last=1,title="lag 2" ,color=colorColumns,linewidth=w)
  92. plot(c3 ,style=plot.style_histogram,offset=m*-48,show_last=1,title="lag 3" ,color=colorColumns,linewidth=w)
  93. plot(c4 ,style=plot.style_histogram,offset=m*-47,show_last=1,title="lag 4" ,color=colorColumns,linewidth=w)
  94. plot(c5 ,style=plot.style_histogram,offset=m*-46,show_last=1,title="lag 5" ,color=colorColumns,linewidth=w)
  95. plot(c6 ,style=plot.style_histogram,offset=m*-45,show_last=1,title="lag 6" ,color=colorColumns,linewidth=w)
  96. plot(c7 ,style=plot.style_histogram,offset=m*-44,show_last=1,title="lag 7" ,color=colorColumns,linewidth=w)
  97. plot(c8 ,style=plot.style_histogram,offset=m*-43,show_last=1,title="lag 8" ,color=colorColumns,linewidth=w)
  98. plot(c9 ,style=plot.style_histogram,offset=m*-42,show_last=1,title="lag 9" ,color=colorColumns,linewidth=w)
  99. plot(c10,style=plot.style_histogram,offset=m*-41,show_last=1,title="lag 10",color=colorColumns,linewidth=w)
  100. plot(c11,style=plot.style_histogram,offset=m*-40,show_last=1,title="lag 11",color=colorColumns,linewidth=w)
  101. plot(c12,style=plot.style_histogram,offset=m*-39,show_last=1,title="lag 12",color=colorColumns,linewidth=w)
  102. plot(c13,style=plot.style_histogram,offset=m*-38,show_last=1,title="lag 13",color=colorColumns,linewidth=w)
  103. plot(c14,style=plot.style_histogram,offset=m*-37,show_last=1,title="lag 14",color=colorColumns,linewidth=w)
  104. plot(c15,style=plot.style_histogram,offset=m*-36,show_last=1,title="lag 15",color=colorColumns,linewidth=w)
  105. plot(c16,style=plot.style_histogram,offset=m*-35,show_last=1,title="lag 16",color=colorColumns,linewidth=w)
  106. plot(c17,style=plot.style_histogram,offset=m*-34,show_last=1,title="lag 17",color=colorColumns,linewidth=w)
  107. plot(c18,style=plot.style_histogram,offset=m*-33,show_last=1,title="lag 18",color=colorColumns,linewidth=w)
  108. plot(c19,style=plot.style_histogram,offset=m*-32,show_last=1,title="lag 19",color=colorColumns,linewidth=w)
  109. plot(c20,style=plot.style_histogram,offset=m*-31,show_last=1,title="lag 20",color=colorColumns,linewidth=w)
  110. plot(c21,style=plot.style_histogram,offset=m*-30,show_last=1,title="lag 21",color=colorColumns,linewidth=w)
  111. plot(c22,style=plot.style_histogram,offset=m*-29,show_last=1,title="lag 22",color=colorColumns,linewidth=w)
  112. plot(c23,style=plot.style_histogram,offset=m*-28,show_last=1,title="lag 23",color=colorColumns,linewidth=w)
  113. plot(c24,style=plot.style_histogram,offset=m*-27,show_last=1,title="lag 24",color=colorColumns,linewidth=w)
  114. plot(c25,style=plot.style_histogram,offset=m*-26,show_last=1,title="lag 25",color=colorColumns,linewidth=w)
  115. plot(c26,style=plot.style_histogram,offset=m*-25,show_last=1,title="lag 26",color=colorColumns,linewidth=w)
  116. plot(c27,style=plot.style_histogram,offset=m*-24,show_last=1,title="lag 27",color=colorColumns,linewidth=w)
  117. plot(c28,style=plot.style_histogram,offset=m*-23,show_last=1,title="lag 28",color=colorColumns,linewidth=w)
  118. plot(c29,style=plot.style_histogram,offset=m*-22,show_last=1,title="lag 29",color=colorColumns,linewidth=w)
  119. plot(c30,style=plot.style_histogram,offset=m*-21,show_last=1,title="lag 30",color=colorColumns,linewidth=w)
  120. plot(c31,style=plot.style_histogram,offset=m*-20,show_last=1,title="lag 31",color=colorColumns,linewidth=w)
  121. plot(c32,style=plot.style_histogram,offset=m*-19,show_last=1,title="lag 32",color=colorColumns,linewidth=w)
  122. plot(c33,style=plot.style_histogram,offset=m*-18,show_last=1,title="lag 33",color=colorColumns,linewidth=w)
  123. plot(c34,style=plot.style_histogram,offset=m*-17,show_last=1,title="lag 34",color=colorColumns,linewidth=w)
  124. plot(c35,style=plot.style_histogram,offset=m*-16,show_last=1,title="lag 35",color=colorColumns,linewidth=w)
  125. plot(c36,style=plot.style_histogram,offset=m*-15,show_last=1,title="lag 36",color=colorColumns,linewidth=w)
  126. plot(c37,style=plot.style_histogram,offset=m*-14,show_last=1,title="lag 37",color=colorColumns,linewidth=w)
  127. plot(c38,style=plot.style_histogram,offset=m*-13,show_last=1,title="lag 38",color=colorColumns,linewidth=w)
  128. plot(c39,style=plot.style_histogram,offset=m*-12,show_last=1,title="lag 39",color=colorColumns,linewidth=w)
  129. plot(c40,style=plot.style_histogram,offset=m*-11,show_last=1,title="lag 40",color=colorColumns,linewidth=w)
  130. plot(c41,style=plot.style_histogram,offset=m*-10,show_last=1,title="lag 41",color=colorColumns,linewidth=w)
  131. plot(c42,style=plot.style_histogram,offset=m*-9 ,show_last=1,title="lag 42",color=colorColumns,linewidth=w)
  132. plot(c43,style=plot.style_histogram,offset=m*-8 ,show_last=1,title="lag 43",color=colorColumns,linewidth=w)
  133. plot(c44,style=plot.style_histogram,offset=m*-7 ,show_last=1,title="lag 44",color=colorColumns,linewidth=w)
  134. plot(c45,style=plot.style_histogram,offset=m*-6 ,show_last=1,title="lag 45",color=colorColumns,linewidth=w)
  135. plot(c46,style=plot.style_histogram,offset=m*-5 ,show_last=1,title="lag 46",color=colorColumns,linewidth=w)
  136. plot(c47,style=plot.style_histogram,offset=m*-4 ,show_last=1,title="lag 47",color=colorColumns,linewidth=w)
  137. plot(c48,style=plot.style_histogram,offset=m*-3 ,show_last=1,title="lag 48",color=colorColumns,linewidth=w)
  138. plot(c49,style=plot.style_histogram,offset=m*-2 ,show_last=1,title="lag 49",color=colorColumns,linewidth=w)
  139. plot(c50,style=plot.style_histogram,offset=m*-1 ,show_last=1,title="lag 50",color=colorColumns,linewidth=w)
  140.  
  141. colorPlotShape = color.new(color.white,50)
  142. 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)
  143. 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)
  144. 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)
  145. 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)
  146. 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)
  147. 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)
  148. 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)
  149. 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)
  150. 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)
  151. 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)
  152. 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)
  153.  
  154. hline(0)
  155. hline(CV1)
  156. hline(CV2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement