I wasn't going to extrapolate or add more to this indicator, but I decided to run the deep fix anyway to show others how to use Garman-Klass volatility on intraday timeframes. Enjoy!
Converted calculation to raw current timeframe volatility calculation. The function garmamKlass returns the current TF volatility in percent form which is then used to create the volatility bands. This should now work in every time and with every asset.
The Garman-Klass volatility measure can be viewed as an extension of the Parkinson volatility measure that includes opening and closing prices.
In 1980, Parkinson introduced the first advanced volatility estimator [6] based only on high and low prices (HL), which can be daily, weekly, monthly, or other:
VP= n∑4ln2(ui−di)2
Step 1: Calculate Parkinson sum: (1 / (2* period) ) * ∑math.log(high/low)^2
As it does not take into account the opening jumps, the Parkinson volatility estimator tends to underestimate the volatility. On the other hand, since it does not handle drift (μ = 0), in a trendy market VP may overestimate the volatility in the pertinent time interval.
In the same year (1980), and in the same journal issue as Parkinson, Garman and Klass proposed their estimator, which is based on all commonly available prices of the current day of trading (OHLC):
Step 2: Calculate the sum of Garman–Klass modifier that adds open/close prices: (1 / period) * (2 * math.log(2) − 1) * ∑math.log(close/open)^2
The Garman–Klass estimator includes opening and closing prices for the current trading day. From this perspective, the VGK estimator extends and improves the performance offered by the Parkinson estimator. It does not include the overnight jumps though; therefore, it may underestimate the volatility. If the opening price is not available, the estimator may use the closing price for the previous day of trading. In this context, the VGK estimator handles the overnight jumps but does not isolate potential opening jumps.
Step 3: Subtract the GK modifier from the Parkinson sum: (step 1 output) - (step 2 output)
Step 4: Take the square root of Step 3 output: math.sqrt(step 3 output)
This final output is the current timeframe volatlity as a percent.
Step 5: Multiply this % volatility by the input source price yeilding a deviation in price
Step 6: Create upper/lower bands by adding and subtracting this deviation multiplied by the input multiplier to the MA you choose
Step 2: Calculate Parkinson sum: (1 / (2* period) ) * SUM => 0 to per [math.log(high/low)^2]