Ulcer Index, rolling high (ULCER_ROLL)
Summary
The Ulcer Index over a rolling high: the root mean square of the last N percent drawdowns, each taken from the highest value of the N bars ending there. It reads downside volatility only: 0 while the series keeps making new highs, rising with the depth and the duration of declines; upside swings do not count. The Ulcer Index is the denominator of the Martin ratio (Ulcer Performance Index).
Chart
Chart metadata i
Outputs
outReal:line
Formula
with = optInTimePeriod.
Notes
- The input is assumed positive. The high of each bar's window is the divisor. Where it is exactly 0 the bar counts as no drawdown. A series that reaches or crosses zero, such as an oscillator or a spread, has no meaningful result here: a high near zero is a small divisor and the output can be very large; no error is returned.
- The high rolls with each bar, the form StockCharts and TradingView publish: a drawdown is measured from a high up to N-1 bars before its own bar. In Peter Martin's original the high starts over at the first bar of each N-bar window, so a drawdown there is measured only from a high inside the window.
- A drawdown reads the N-1 bars before its own and the mean spans N drawdowns, so the first value needs 2N-1 bars.
- The result is in percent, between 0 and 100 on positive input: 5 is a root-mean-square drawdown of 5% of the high.
Inputs
inReal— Input price series
Outputs
outReal— Root mean square of the percent drawdowns from the rolling high
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 14 | 2–10000 | Bars in the rolling high, and drawdowns in the mean |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ✅ Input Must Be Positive i |
Example
C
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_ULCER_ROLL( 0, n - 1, series, 14, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d: [%.4f, ..., %.4f]\n", outNBElement, outBegIdx, out[0], out[outNBElement - 1] );Rust
use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.ulcer_roll(0, series.len() - 1, &series, 14, &mut out)?;
println!("{} values from bar {}: [{:.4}, ..., {:.4}]", range.count, range.beg_idx, out[0], out[range.count - 1]);Java
import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.ulcerRoll(0, series.length - 1, series, 14, out);
System.out.printf(Locale.ROOT, "%d values from bar %d: [%.4f, ..., %.4f]%n", r.count(), r.begIdx(), out[0], out[r.count() - 1]);C#
using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.UlcerRoll(0, series.Length - 1, series, 14, outReal);
Console.WriteLine(FormattableString.Invariant($"{r.Count} values from bar {r.BegIdx}: [{outReal[0]:F4}, ..., {outReal[r.Count - 1]:F4}]"));TypeScript
import { ulcerRoll } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = ulcerRoll(series, { timePeriod: 14 });
console.log(values.length + ' values from bar ' + begIdx + ': [' + values[0]?.toFixed(4) + ', ..., ' + values[values.length - 1]?.toFixed(4) + ']');Go
import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
series := make([]float64, 252) // your data, oldest first
out := make([]float64, 252)
core := talib.NewCore()
r, err := core.ULCER_ROLL(0, len(series)-1, series, 14, out)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d: [%.4f, ..., %.4f]\n", r.NBElement, r.BegIdx, out[0], out[r.NBElement-1])Implementation
Added in 0.8.4.
TA-Lib Definition: ulcer_roll.c · ulcer_roll.yaml
| Native | File |
|---|---|
| C | ta_ULCER_ROLL.c |
| Rust | ulcer_roll.rs |
| Java | Core_ULCER_ROLL.java |
| C# | Core_ULCER_ROLL.cs |
| TypeScript | ulcerRoll.ts |
| Go | ulcer_roll.go |
Python: talib.ULCER_ROLL, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Ulcer Index, UI
See Also
References
- Peter G. Martin and Byron B. McCann, The Investor's Guide to Fidelity Funds, John Wiley & Sons 1989
- Ulcer Index, StockCharts ChartSchool
- Ulcer Index, TradingView Help Center