| Miscellaneous > Hist Volatility [eSignal EFS Indicators]
Download: HistVolatility.efs
Category: Indicator > Miscellaneous
Description:
Markets oscillate from periods of low volatility to high volatility and back. The author`s research indicates that after periods of extremely low volatility, volatility tends to increase and price may move sharply. This increase in volatility tends to correlate with the beginning of short- to intermediate-term moves in price. They have found that we can identify which markets are about to make such a move by measuring the historical volatility and the application of pattern recognition.
The indicator is calculating as the standard deviation of day-to-day logarithmic closing price changes expressed as an annualized percentage.
Inputs:
Lookbck - lookback period
Annual - number of days in year
EFS Code:/*******************************************************************
Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
********************************************************************/
function preMain()
{
setPriceStudy(false);
setStudyTitle("Hist Volatility");
setCursorLabelName("HisVol");
}
function main(LookBack, Annual)
{
if (LookBack == null) LookBack = 20;
if (Annual == null) Annual = 365;
var Interval = getInterval();
var Per = 0;
if (Interval == "1") Per = 1;
if (Interval == "5") Per = 1;
if (Interval == "10") Per = 1;
if (Interval == "15") Per = 1;
if (Interval == "D") Per = 1;
if (Per == 0) Per = 7;
var Close = getValue("Close", 0, -(LookBack + 1));
var Price = Math.log(Close[0] / Close[1]);
if (LookBack <= 0) return;
var Avg = 0.0;
var i = 0;
for (i = 0; i < LookBack; i++)
{
Price = Math.log(Close[i] / Close[i + 1]);
Avg += Price;
}
Avg /= LookBack;
var SumSqr = 0.0;
for (i = 0; i < LookBack; i++)
{
Price = Math.log(Close[i] / Close[i + 1]);
SumSqr += (Price - Avg) * (Price - Avg);
}
var StdDev = Math.sqrt(SumSqr / LookBack);
var HVol = (StdDev * Math.sqrt(Annual / Per)) * 100;
return HVol;
}
|