ITMScript
Measure realised volatility
Show realised volatility as an annual percentage, using a bars-per-year count that you declare.
Show the spread of one-bar log returns over a window, scaled to a year.
//@itmscript 2
study("Realised volatility", overlay=false)
len = input.int(20, "Window", min=5, max=500)
periods = input.int(252, "Bars per year", min=1, max=100000)
vol = ta.realizedvol(close, len, periods) * 100
plot(vol, "Volatility, percent", color=color.purple, width=2, style=line)
plot(ta.sma(vol, len), "Average", color=color.gray, width=1, style=line)What you see
A purple line in its own pane shows the volatility in percent a year. A grey line shows its own average over the same window. The line starts once the window has filled.
The study scales the spread of returns by the square root of the number of bars in a year. It does not work that number out from the timeframe, because the timeframe says nothing about how many bars a year holds.
Change these inputs
- Window. The number of bars in the rolling window, from 5 to 500.
- Bars per year. The number of bars in a trading year. Use 252 on daily bars. On intraday bars, multiply 252 by the number of bars in a session.