Yang-Zhang Volatility Estimator
Range-based volatility estimators like Parkinson or Garman-Klass are more efficient than plain close-to-close standard deviation, but most of them quietly assume price never jumps between one bar's close and the next bar's open. That assumption is false on forex every single weekend, and false on indices every session open. Yang-Zhang fixes this by explicitly modelling the overnight leg as its own variance term - the log difference between a bar's open and the PREVIOUS bar's close - and combining it with the open-to-close variance and the Rogers-Satchell range term using a weighting constant Yang and Zhang derived to minimise the blended estimator's own variance. The result is a volatility read that is both drift independent (it does not assume returns average to zero, unlike a naive stdev over a small sample) and gap aware (it does not throw away the information in a weekend or opening jump). A plain close-to-close line is plotted alongside it for direct comparison. The gap between the two widens visibly across weekend bars and session-open bars on gappy instruments, which is exactly the behaviour Yang-Zhang is built to capture correctly. Notes and limitations - The Rogers-Satchell component of the blend can individually be negative on very quiet bars; the combined variance is floored at zero before taking the square root so the line never goes undefined. - Like all discretely sampled estimators built from OHLC data, this is known to run slightly biased relative to true continuous volatility - an accepted property of the method, not an implementation error. - Expressed in native per-bar percentage terms, not annualised, since annualising needs assumptions about trading days that vary by broker and symbol. - This describes volatility, not direction. It does not size a position or place a stop.
Indicator · MT4 · v1.0 · Free
About Yang-Zhang Volatility Estimator
Yang-Zhang Volatility Estimator is an indicator for MetaTrader 4. It has 1 setting, such as Period. MQL source code included.
Files in the download: YangZhangVolatility.ex4, YangZhangVolatility.mq4, YangZhangVolatility.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Period | 20 | Rolling window, in bars, for the estimator |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Trading Sessions · MT4 Indicator · MQL4 Source Code