Loading…

Volume Surprise Detector

Most "volume spike" tools compare the current bar to a fixed multiple of a simple moving average of volume - a threshold that is far too loose in a quiet regime and far too tight in a busy one. This indicator instead computes a proper z-score: for every bar it builds the mean and standard deviation of tick volume over the trailing InpLookback bars, then measures how many standard deviations the current bar's volume sits above that forecast. A bar only counts as a surprise once its z-score clears InpZThreshold, which naturally tightens the effective volume bar during quiet stretches and loosens it during genuinely busy ones, because the trailing standard deviation moves with the regime. Colour-by-state is done with the split-buffer trick this catalogue uses throughout its MQL4 side, since native MQL4 has no DRAW_COLOR_HISTOGRAM: one buffer holds every ordinary bar's volume, a second holds only the flagged bars' volume, both aligned to the same histogram position so a surprise bar reads as a colour change rather than needing a separate marker object. The naive version of this idea flags anything above 1.5x or 2x a moving average, which produces constant false positives the moment average volume itself trends up or down. Building the forecast from the bars' own recent dispersion, not just their level, is the specific fix. Notes and limitations - Every volume figure is MT4 tick volume (price update count), never real traded contracts or lots. - The forecast needs InpLookback bars of history behind each bar; the very first InpLookback bars on the chart show no value. - A symbol with genuinely near-constant volume (a very quiet synthetic/basket symbol) can produce a near-zero standard deviation, which makes even a small absolute volume change register as a large z-score - widen InpLookback if this produces too many flags on such a symbol. - No trade or alert logic - visual analysis only.

Indicator · MT5 · v1.0 · Free

About Volume Surprise Detector

Volume Surprise Detector is an indicator for MetaTrader 5. It has 3 settings, such as Lookback, Z threshold and Max bars to process. MQL source code included.

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

Settings

SettingDefaultWhat it does
Lookback20Trailing bars used to build each bar's own mean/stddev forecast
Z threshold2.0Bars whose z-score clears this value are flagged as a surprise
Max bars to process2000Hard cap on bars recalculated on a fresh attach/history load

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 → Indicators.
  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 indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Moving Average · Volume · Trailing Stop & Break-even · MT5 Indicator · MQL5 Source Code

MetaTrader 4 & 5 indicators · PolyMaria