This article implements the Garman–Klass volatility estimator as an MQL5 indicator that uses OHLC data for higher statistical efficiency than close-to-close measures. A percentile-based squeeze/expansion detector produces breakout signals, and a companion Expert Advisor executes them via iCustom. Implementation details include series-aware indexing, recursive squeeze-state handling in indicator buffers, and a baseline-on-attach rule for the EA, giving a ready-to-use toolkit for volatility-regime trading.
Volatility is the single most fundamental quantity in trading — it determines position sizing, stop placement, option pricing, and regime classification. Yet the most common volatility measure used in retail trading, close-to-close volatility, uses only one of the four prices each bar records. This is not literally “three-quarters of the information,” since the open, high, and low of a single bar are not four independent observations — the high and low are constrained by the same bar's own price path, and the open is often close to the previous bar's close — but the high and low do carry genuine intrabar information about how far price actually traveled, information close-to-close volatility discards entirely.
This waste has a measurable cost. When volatility is underestimated, positions are oversized for the actual risk. When it is overestimated, opportunities are left on the table. And when a volatility regime shift happens — from quiet consolidation to explosive breakout — a sluggish estimator detects it bars or even sessions too late.
In practice, building a better volatility tool for live trading presents three challenges:
First, the estimator must use all available OHLC information efficiently, not just closing prices. Second, raw volatility values must be translated into actionable regime signals — a number that says "volatility is 0.23" is difficult to act on without context about whether that is historically high or low. Third, any regime-detection mechanism that carries state from bar to bar (like a squeeze flag) must handle the recursive bookkeeping correctly in MQL5's indicator buffer system, or the state silently corrupts itself on every new bar.
This article works through all three. We begin with the Garman–Klass (1980) variance estimator, verify its efficiency gain in Python, build a percentile-based squeeze-expansion detection system around it, implement the full indicator in MQL5, and connect it to an Expert Advisor that trades volatility breakouts.
Check out the new article: Efficient Volatility Estimation with Garman–Klass: From Theory to a Percentile-Based Trading Tool in MQL5.
Volatility is the single most fundamental quantity in trading — it determines position sizing, stop placement, option pricing, and regime classification. Yet the most common volatility measure used in retail trading, close-to-close volatility, uses only one of the four prices each bar records. This is not literally “three-quarters of the information,” since the open, high, and low of a single bar are not four independent observations — the high and low are constrained by the same bar's own price path, and the open is often close to the previous bar's close — but the high and low do carry genuine intrabar information about how far price actually traveled, information close-to-close volatility discards entirely.
This waste has a measurable cost. When volatility is underestimated, positions are oversized for the actual risk. When it is overestimated, opportunities are left on the table. And when a volatility regime shift happens — from quiet consolidation to explosive breakout — a sluggish estimator detects it bars or even sessions too late.
In practice, building a better volatility tool for live trading presents three challenges:
First, the estimator must use all available OHLC information efficiently, not just closing prices. Second, raw volatility values must be translated into actionable regime signals — a number that says "volatility is 0.23" is difficult to act on without context about whether that is historically high or low. Third, any regime-detection mechanism that carries state from bar to bar (like a squeeze flag) must handle the recursive bookkeeping correctly in MQL5's indicator buffer system, or the state silently corrupts itself on every new bar.
This article works through all three. We begin with the Garman–Klass (1980) variance estimator, verify its efficiency gain in Python, build a percentile-based squeeze-expansion detection system around it, implement the full indicator in MQL5, and connect it to an Expert Advisor that trades volatility breakouts.
Author: Syed Jawad Hussain Naqvi