Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("AutoCorrelation",precision=3)
- len=input(60)
- lag=input(1)
- src=input(close)
- m=input(30,"ma")
- S=input(false,"Spearman Correlation")
- Detrend = input(title="Detrend", type=input.string, defval="Difference", options=["Difference","Log Return"])
- pm = input(false,"plot ma")
- //Difference
- d=src-src[1]
- d1=percentrank(d,len)
- d2=percentrank(d[lag],len)
- //cc
- c1=S?correlation(d1,d2,len):correlation(d,d[lag],len)
- //Log
- l=log(src[0]/src[1])
- l1=percentrank(l,len)
- l2=percentrank(l[lag],len)
- //cc
- c2=S?correlation(l1,l2,len): correlation(l,l[lag],len)
- Ac = Detrend == "Difference" ? c1 : Detrend == "Log Return" ? c2: na
- ma=sma(Ac,m)
- CV1 = 1.96/sqrt(len)
- CV2 = -(CV1)
- plot(Ac,transp=0,color=Ac>0?color.blue:color.red,style=plot.style_columns)
- plot(pm?ma:na,color=color.green,transp=0,linewidth=2)
- hline(0)
- hline(CV1)
- hline(CV2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement