How it is calculated
Each bar's log return is the natural log of the close over the previous close. HV is the population standard deviation of the last length log returns, times the square root of annual (bars per year), times 100. A close of 0 or below, or a ratio too extreme for a float, has no return: the window starts over and the line comes back after length valid returns. Close to close volatility.
Reference: Close to close volatility (annualised population deviation of log returns)
How to read it
An HV of 20 means the closes moved as if the yearly standard deviation were about 20 percent. Compare it with its own history or with implied volatility. annual must match the timeframe, 252 for daily stock bars or 365 for daily crypto bars; a wrong value scales the whole line.
In a strategy
Scale position size inversely to volatility, or trade only while ctx.ind("hv", length=20, annual=252) is below a level such as 40, so a strategy carries a similar risk in calm and wild markets.
Inputs
| Input | Type | Default | Range or choices |
|---|---|---|---|
Lengthlength | Whole number | 10 | min 2, max 5000 |
Bars per yearannual | Whole number | 252 | min 1, max 100000 |
What it draws
| Line | Drawn as |
|---|---|
| HV | Line |
Used in
No strategy template reads it yet.