Historical Volatility

Historical volatility is a measure of volatility over a fixed span of time.

Historical volatility is calculated by taking the standard deviation of the natural log of the ratio of consecutive closing prices over time.  This is multiplied by the square root of the number of bars in a year so it can be compared to other time spans and multiplied by 100 to convert it to a percentage.

Custom PCF Formula
1600 * ABS((SUM(LOG(C / C1) ^ 2, x) - LOG(C / Cx) ^ 2 / x) / x) ^ .5
x=Period

Where x is the period which must be an integer.

This indicator template is for daily and will not automatically adjust when you change time frames.

The 1600 at the beginning is 100 times the square root of 256. So this formula assumes a daily time frame with 256 daily bars during the year.

The 256 bars per year is chosen more for being an even square as being the most accurate number of daily bars in the average year. Most people use between 250 and 260 for the average number of bars in a year, so 256 should be fine.

If this the formula used a weekly time frame for example you could use 721 or possibly 100 * SQR(52) instead (even though there is a fraction of a week more than 52 weeks in a year).

Examples

A 6 period Historical Volatility for a daily time frame can be written as follows.

1600 * ABS((SUM(LOG(C / C1) ^ 2, 6) - LOG(C / C6) ^ 2 / 6) / 6) ^ .5

A 100 period Historical Volatility for a daily time frame can be written as follows.

1600 * ABS((SUM(LOG(C / C1) ^ 2, 100) - LOG(C / C100) ^ 2 / 100) / 100) ^ .5