Loading…

Half-Range Mode Estimator

Every moving average - simple, exponential, weighted - answers the same underlying question: what is the mean price over the window. This indicator answers a different question: what price did the window spend the most time near. That is the statistical mode, and for continuous data like price there is no single bar that repeats exactly, so the mode has to be estimated rather than counted directly. The estimator used here is the half-range mode (also known as the half-sample mode, or the "shorth" family in robust statistics): sort the window's closes, then repeatedly discard the wider half of the sorted values and keep whichever contiguous half spans the smallest price range, until a small core of values remains, and average that core. Because the method only ever looks at which values are closest together - never how large a single outlier is - a handful of spike closes are simply the values most likely to be discarded in the very first halving pass, so they barely move the final estimate. This is the same robustness property Median Absolute Deviation Bands (I235) brings to spread, applied here to a centre line instead. The result tracks the price level where the window's closes actually clustered, which during a range-bound stretch sits at the middle of the range as expected, but during a move that spends most of its time near one extreme and only briefly touches the other, the half-range mode sits closer to where price actually lingered - somewhere a simple or exponential average, which is pulled toward every bar equally, does not. Notes and limitations - The halving stops once three or fewer values remain and averages that final core; this is a deliberate stopping point rather than reducing all the way to a single value, which would make the estimate too sensitive to the exact sort order of near-tied prices. - Recomputed from scratch (full sort plus iterative halving) on every bar over the fixed window; this is a plain, correct implementation rather than an incrementally maintained running estimate, and is fast enough for any reasonable InpPeriod on a single-symbol chart. - On a strongly trending market with no meaningful clustering (price moves steadily rather than lingering anywhere), the half-range mode behaves similarly to a short moving average - the distinct benefit shows up specifically in ranging or one-sided-dwell price action. - This is a centre-line overlay only; it does not generate trade signals, alerts, or classify the market regime on its own.

Indicator · MT4 · v1.0 · Free

About Half-Range Mode Estimator

Half-Range Mode Estimator is an indicator for MetaTrader 4. It has 1 setting, such as Period. MQL source code included.

Files in the download: HalfRangeModeMa.ex4, HalfRangeModeMa.mq4, HalfRangeModeMa.txt.

Settings

SettingDefaultWhat it does
Period30Rolling sample window in bars

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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 · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria