Pabloadmin
New member
Hi, i share this historic volatility indicator, if you wanted compair HV between instruments.
It's same HistoricVolatility indicator that come TOS but you can especify the instrument to analice.
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
declare lower;
input length = 20;
input basis = {default Annual, Monthly, Weekly, Daily};
input Instrument = "";
def ap = getAggregationPeriod();
assert(ap >= AggregationPeriod.MIN, "Study can only be calculated for time-aggregated charts: " + ap);
def barsPerDay = (regularTradingEnd(getYyyyMmDd()) - regularTradingStart(getYyyyMmDd())) / ap;
def barsPerYear =
if ap > AggregationPeriod.WEEK then 12
else if ap == AggregationPeriod.WEEK then 52
else if ap >= AggregationPeriod.DAY then 252 * AggregationPeriod.DAY / ap
else 252 * barsPerDay;
def basisCoeff;
switch (basis) {
case Annual:
basisCoeff = 1;
case Monthly:
basisCoeff = 12;
case Weekly:
basisCoeff = 52;
case Daily:
basisCoeff = 252;
}
def stock = close(Instrument, period = ap);
def clLog = log(stock / stock[1]);
plot HV = stdev(clLog, length) * Sqrt(barsPerYear / basisCoeff * length / (length - 1));
HV.SetDefaultColor(GetColor(0));
It's same HistoricVolatility indicator that come TOS but you can especify the instrument to analice.
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
declare lower;
input length = 20;
input basis = {default Annual, Monthly, Weekly, Daily};
input Instrument = "";
def ap = getAggregationPeriod();
assert(ap >= AggregationPeriod.MIN, "Study can only be calculated for time-aggregated charts: " + ap);
def barsPerDay = (regularTradingEnd(getYyyyMmDd()) - regularTradingStart(getYyyyMmDd())) / ap;
def barsPerYear =
if ap > AggregationPeriod.WEEK then 12
else if ap == AggregationPeriod.WEEK then 52
else if ap >= AggregationPeriod.DAY then 252 * AggregationPeriod.DAY / ap
else 252 * barsPerDay;
def basisCoeff;
switch (basis) {
case Annual:
basisCoeff = 1;
case Monthly:
basisCoeff = 12;
case Weekly:
basisCoeff = 52;
case Daily:
basisCoeff = 252;
}
def stock = close(Instrument, period = ap);
def clLog = log(stock / stock[1]);
plot HV = stdev(clLog, length) * Sqrt(barsPerYear / basisCoeff * length / (length - 1));
HV.SetDefaultColor(GetColor(0));