♥ 0 |
Hey guys, I’m trying to create a chart label that displays the Historic Volatility onto a chart label with the % to match the one on the options chain. I’m somewhat familiar with the Add Label feature, but having difficulty making sense of the formula in order to make it work properly. I keep getting odd results that don’t match the HV on the options chain. For example, the chart label’s HV should match the HV in the chain screenshot. The script included is from TOS .
Marked as spam
|
Please log in to post questions.
plot Data = close;
declare lower;
input length = 20;
input basis = {default Annual, Monthly, Weekly, Daily};
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 clLog = log(close / close[1]);
plot HV = stdev(clLog, length) * Sqrt(barsPerYear / basisCoeff * length / (length – 1));
HV.SetDefaultColor(GetColor(0));
AddLabel(yes,Round( HV,2) +”%”, color.blue);