Volatility Ratio Adaptive Envelope
A plain percent envelope's width is a single static guess. It is too tight the moment volatility expands beyond its recent baseline - price punches through repeatedly and stops out anything using the band as a boundary - and too loose once volatility settles back down, trailing price uselessly far away and giving late, low-quality signals either way. This version replaces the fixed width with InpBaseWidthPercent multiplied by a ratio: short-period close standard deviation divided by long-period close standard deviation. When recent volatility is running above its own longer-run baseline the ratio exceeds one and the envelope widens with it; when volatility has calmed back toward baseline the ratio drops toward one and the envelope tightens back to its base width. The ratio is clamped between InpMinRatio and InpMaxRatio so one abnormal bar in the short window cannot blow the envelope out to an unusable width, and a near-silent long window cannot collapse it to nothing either. Notes and limitations - Volatility here is close-price standard deviation, not ATR - it reacts to closing price dispersion specifically, which can differ from a range-based reading during sessions with large wicks but similar closes. - Non-repainting: every bar's basis and band are computed only from that bar's own completed history. - Purely a visual envelope. It draws no arrows and sends no alerts.
Indicator · MT4 · v1.0 · Free
About Volatility Ratio Adaptive Envelope
Volatility Ratio Adaptive Envelope is an indicator for MetaTrader 4. It has 6 settings, such as Ma period, Short vol period and Long vol period. MQL source code included.
Files in the download: VolatilityRatioEnvelope.mq4, VolatilityRatioEnvelope.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Ma period | 20 | Basis simple moving average period |
| Short vol period | 10 | Short-term volatility window, in bars |
| Long vol period | 50 | Long-term (baseline) volatility window, in bars |
| Base width percent | 2.0 | Envelope half-width at a volatility ratio of 1.0, in percent of basis |
| Min ratio | 0.5 | Floor on the short/long volatility ratio, prevents the band collapsing to zero |
| Max ratio | 3.0 | Ceiling on the short/long volatility ratio, prevents one spike bar blowing the band out |
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: Moving Average · Channels & Envelopes · Buy/Sell Arrows · Trailing Stop & Break-even · MT4 Indicator · MQL4 Source Code