OPEN-SOURCE SCRIPT

Ulcer Index (UI) by CoryP1990 – Quant Toolkit

105
The Ulcer Index measures downside volatility, i.e. how deep and persistent drawdowns are from recent highs. Unlike standard deviation, which treats upside and downside equally, the Ulcer Index focuses purely on pain. It’s a favorite of risk-adjusted performance metrics like the Martin Ratio.

How it works

Computes the RMS (root-mean-square) of drawdowns over a look-back window.

Rising UI → drawdowns worsening (stress increasing).

Falling UI → drawdowns shrinking (recovery phase).

Red line = Ulcer Index rising.

Lime line = Ulcer Index falling.

Red background = High-risk regime (above threshold).

Green background = Low-risk regime (below threshold).

Use cases

Gauge portfolio stress levels and timing of recovery phases.

Identify “calm vs storm” periods for position sizing.

Combine with volatility or sentiment measures for regime classification.

Defaults

Length = 14

High-risk threshold = 10

Low-risk threshold = 5

Example — NVIDIA (NVDA, 1D)

During the sharp decline through 2022, the Ulcer Index repeatedly spiked above 10 while the background turned red, highlighting an extended high-stress drawdown phase. As NVDA began recovering in early 2023, the UI line switched to lime and drifted below 5, marking a transition into a low-risk regime. Throughout 2024–2025, the index stayed mostly sub-5 with brief red pulses on minor corrections, which is clear evidence that downside volatility has remained contained during the broader uptrend.

Part of the Quant Toolkit - a series of transparent, open-source indicators designed for professional-grade analytics and education. Built by CoryP1990.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.