Loading…

Ulcer Index

Standard deviation treats a slow grind to a new high exactly the same as a sharp plunge - both count as "volatility". The Ulcer Index does not: at every bar in its rolling window it computes a percentage drawdown against that bar's own trailing highest close (not one fixed high for the whole calculation - each bar looks back over its own InpPeriod-bar window), so a bar sitting at a new high always scores zero. Only bars sitting below their own recent high contribute, and because the drawdowns are squared before being averaged and square-rooted, one deep drawdown pulls the reading up far more than several shallow ones of the same total size - which is closer to how a drawdown actually feels to hold through, and the reason Martin named it after the thing it was meant to measure. The result is a single number that rises when price is grinding below its recent highs and falls back toward zero once price is making new highs again. It says nothing about direction or trend strength; it is purely a measure of how much pain a period of holding the instrument would have involved. Notes and limitations - Needs 2 x InpPeriod - 1 bars of close history before the first value appears, because every bar in the outer window needs its own trailing high computed from a further InpPeriod bars behind it; earlier bars are intentionally left empty rather than guessed. - Fully recomputed from raw closes at every bar rather than tracked incrementally, so a data gap or a changed InpPeriod can never leave a stale running sum behind, and nothing here can repaint once a bar closes. - Downside-only by design - it will read zero or near-zero through a strong uptrend even if that uptrend is volatile bar to bar, because new highs contribute nothing to the sum. - Not a percentage of account equity or a risk-of-ruin figure; it is a price-series statistic, useful for comparing the drawdown character of different instruments or periods, not for position sizing on its own.

Indicator · MT4 · v1.0 · Free

About Ulcer Index

Ulcer Index is an indicator for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Period, Alert level and Alerts. MQL source code included.

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

Settings

SettingDefaultWhat it does
Period14Rolling window, in bars, for both the trailing high and the RMS average
Alert level5.0Alert once when the index rises through this level
AlertstrueAlert once per closed bar on that upward cross

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: Martingale · Trailing Stop & Break-even · Alerts · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria