Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Pig Historical Volatility Mean Absolute Deviation",precision=2)
- H = input(title="Historical Volatility", type=input.string, defval="Yang Zhang", options=["Close Centered","Close Zero Mean","Close Absolute Return","Parkinson","Rogers Satchell","Garman Klass","Garman Klass Yang Zhang Extension","EWMA","Yang Zhang"])
- Annual = input(365, "Annual")
- n = input(30, "Length")
- Plen = input (365, "Percentile Length")
- malen = input (30, "Ma Length")
- xPrice = log(close / close[1])
- sma = input(false, "Plot Moving Average")
- Columns = input(false,"Style Columns")
- PI= 2 * asin(1)
- //Percentrank Formula
- _percentrank(src, length) =>
- count = 0
- for i = 1 to length
- count := count + (src >= nz(src[i]) ? 1 : 0)
- pr = 100 * count / length
- //Close to Close Centered
- dev = xPrice - sma(xPrice, n)
- mad = sum(abs(dev), n) / (n)
- amad=sqrt(Annual*PI/2)*mad
- Hv = amad*100
- //Historical Volatility Percentile
- Hvp=_percentrank(Hv, Plen)
- Color= Hvp >= 95 ? color.new(color.red,0): Hvp >= 80 ? color.new(color.orange,0) : Hvp >= 70 ? color.new(color.yellow,0) : Hvp >= 30 ? color.new(color.blue,0) : Hvp >= 10 ? color.new(color.aqua,0) : Hvp >= 5 ?color.new(color.silver,0) : color.new(color.white,0)
- ma= sma(Hv, malen)
- plot(Hv, color=Color,transp=0,linewidth=2,style= Columns?plot.style_columns : plot.style_line)
- plot(sma?ma:na, color=color.lime, transp=0, linewidth=2)
- hline(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement