Loading…

Volatility Regime Label Dump

Regime-aware strategies need to know, for every historical bar, whether volatility at that point was quiet, normal or extreme - and they need it as data they can join against, not as a chart study that has to be re-derived inside every Expert Advisor that wants to use it. This script produces that data: for each bar in the loaded window it computes ATR, ranks that ATR value against every other bar in the same window, and writes the bar time, ATR in pips, percentile and regime label to a CSV. The percentile is computed against the WHOLE loaded sample, not a trailing window. A rolling percentile needs its own lookback choice, and baking one choice into this script would force it on every downstream consumer. A fixed-sample percentile lets whoever reads the CSV apply their own rolling logic if they want one, without inheriting this script's assumption. Regime boundaries are three percentile thresholds, not fixed ATR values, so the same script produces a sensible split on a quiet pair and a volatile one without the user having to know each instrument's typical ATR in advance. Notes and limitations - The oldest bars in the loaded window have less history behind them for ATR to average over, so their ATR reading is less settled than a bar in the middle of the sample. They are labelled anyway; treat the earliest InpAtrPeriod or so bars in the CSV with that in mind. - The CSV output is not optional - the whole point of this script is the per-bar dump, so there is no InpSaveCsv switch to turn it off. - Percentile is a rank within THIS run's sample only. Running the script again with a different InpMaxBars or a later end date changes the sample and can shift every bar's percentile and regime label. - This is a classification tool, not a trading signal - a bar labelled Extreme says nothing about direction, only that its ATR ranked high against the rest of the loaded window. - On MQL5, if the ATR handle's data is not ready within the 2-second wait (e.g. a freshly attached symbol still syncing history), the script alerts and stops rather than labelling a partial or stale sample - simply run it again once the symbol's history has finished loading.

Script · MT5 · v1.0 · Free

About Volatility Regime Label Dump

Volatility Regime Label Dump is a script for MetaTrader 5 based on ATR. It can alert you with a pop-up, sound, email or push message. It has 8 settings, such as Symbol, Timeframe and Atr period. MQL source code included.

Files in the download: VolatilityRegimeLabelDump.ex5, VolatilityRegimeLabelDump.mq5, VolatilityRegimeLabelDump.txt.

Settings

SettingDefaultWhat it does
SymbolSymbol to study, blank = this chart's symbol
TimeframePERIOD_CURRENTTimeframe to study
Atr period14ATR averaging period
Max bars3000Most recent bars to include
Low percentile25.0Below this percentile = Low regime
High percentile75.0At or above this percentile = High regime
Extreme percentile95.0At or above this percentile = Extreme regime
DelimiterDelimiterCommaCSV column separator

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: ATR · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria