# Historical Volatility in 5m

How to make a historical volatility indicator for a 5-minute chart?

ps. on the daily chart it plots the correct value, but when it changes to 5 minutes the volatility is wrong.

thx

What is the formula you're using for HV? Typically it will include a factor that is the square root of the number of periods in a year. For example, if you're calculating the standard deviation of daily values for the US Market, you multiply by SQRT(252) to annualize the value because there are approximately 252 trading days in a year after accounting for weekends and market holidays. If you want to use 5 minute bars, then you need to determine how many five minute bars are in a typical year for the market you are trading. For the US stock market, that would be 252 days * 6.5 hours/day * 12 bars/hour.

1 Like

Did not work.

I'm using this code for HV:

_SECTION_BEGIN("Historical Volatility");
HVPeriod = Param("HV Period",21,5,252,1);

HV = StDev(log(C/Ref(C,-1)),HVPeriod)*sqrt(252)*100;
Plot(HV,"Historical Volatility",colorYellow,styleLine);
_SECTION_END();

thx!

1 Like

To confirm, you replaced 252 with 19656 if calculating HV using 5 minute bars? If you want approximately the same lookback period (21 days by default in your AFL), you would also need to multiply HVPeriod by 6.5 hours/day * 12 bars/hour.

How did you confirm whether it worked or not? Hopefully it is obvious that you will not get the same result when you annualize the standard deviation of 5-minute returns as when you annualize the daily returns.

1 Like