Advertisement
Guest User

autocorrelation

a guest
Jan 25th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. //@version=4
  2. study("AutoCorrelation",precision=3)
  3. len=input(60)
  4. lag=input(1)
  5. src=input(close)
  6. m=input(30,"ma")
  7. S=input(false,"Spearman Correlation")
  8. Detrend = input(title="Detrend", type=input.string, defval="Difference", options=["Difference","Log Return"])
  9. pm = input(false,"plot ma")
  10.  
  11. //Difference
  12. d=src-src[1]
  13. d1=percentrank(d,len)
  14. d2=percentrank(d[lag],len)
  15. //cc
  16. c1=S?correlation(d1,d2,len):correlation(d,d[lag],len)
  17.  
  18. //Log
  19. l=log(src[0]/src[1])
  20. l1=percentrank(l,len)
  21. l2=percentrank(l[lag],len)
  22. //cc
  23. c2=S?correlation(l1,l2,len): correlation(l,l[lag],len)
  24.  
  25.  
  26. Ac = Detrend == "Difference" ? c1 : Detrend == "Log Return" ? c2: na
  27. ma=sma(Ac,m)
  28.  
  29. CV1 = 1.96/sqrt(len)
  30. CV2 = -(CV1)
  31.  
  32.  
  33. plot(Ac,transp=0,color=Ac>0?color.blue:color.red,style=plot.style_columns)
  34. plot(pm?ma:na,color=color.green,transp=0,linewidth=2)
  35. hline(0)
  36. hline(CV1)
  37. hline(CV2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement