Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("High Frequency Historical Volatility (2)",precision=2)
- bgcolor(#000000c0)
- Annual = input(365,title = "Trading Days in one Year")
- Month = input(30,title = "Trading Days in one Month")
- // Security
- reso = input(defval="5", title="Historical Volatility Sampling Resolution")
- //High Frequency Historical Volatility
- m = input(288, minval=1,title="Number of sampling returns per bar") //Default = 24*60(minutes in one bar(1 day))/5 (sampling resolution) = 288
- k = Annual*m
- n = Month*(m+1)
- //n = (Month-1)*(m+1)
- change = log(close / nz(close[1]))
- variance = sum(pow(change, 2), m)
- v = security(syminfo.tickerid, reso, variance)
- c2 = log(open/nz(close[1])) //Gap
- Hv = sqrt((k/n) * (sum(v+pow(c2,2),Month)))*100
- //Historical Volatility Percentile coloring
- malen = input (30, "Ma Length")
- sma = input(false, "Plot Moving Average")
- Columns = input(false,"Style Columns")
- ma= sma(Hv, malen)
- Hvp = percentrank(Hv, Annual)
- 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)
- plot(Hv, color=Color,transp=0,linewidth=3,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