Indicator · Pine Script v4 · Own pane

Ulcer Index

by everget

Calculates the Ulcer Index indicator to measure downside risk and price drawdowns over a specified lookback period.

View on GitHub

GitHub stars948on the repository
Pine versionv4older, still runs
Lines of code36
Settings9inputs
LicenceGPL-3.0
Last update10 days ago18 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

36 lines of Pine Script v4 from volatility/ulcer_index.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

ulcer_index.pine
//@version=4
// Copyright (c) 2018-present, Alex Orekhov (everget)
// Ulcer Index script may be freely distributed under the terms of GPL-3.0 license.
study("Ulcer Index")

length = input(title="Length", type=input.integer, defval=14)
smoothLength = input(title="Smoothing Length", type=input.integer, defval=14)
breakout = input(title="Breakout Level", type=input.float, step=0.1, defval=1.5)
signalType = input(title="Signal Smoothing Type", defval="SMA", options=["EMA", "SMA"])
signalLength = input(title="Signal Smoothing Length", type=input.integer, defval=52)
src = input(title="Source", type=input.source, defval=close)
showSignal = input(title="Show Signal ?", type=input.bool, defval=true)
highlightCrossovers = input(title="Highlight Signal Crossovers ?", type=input.bool, defval=true)
applyRibbonFilling = input(title="Apply Ribbon Filling ?", type=input.bool, defval=true)

highest = highest(src, length)
drawdown = 100 * (src - highest) / highest
ulcer = sqrt(sma(pow(drawdown, 2), smoothLength))
signal = signalType == "SMA" ? sma(ulcer, signalLength) : ema(ulcer, signalLength)

trendColor = ulcer > signal ? #0ebb23 : color.red
ulcerColor = applyRibbonFilling ? trendColor : (ulcer >= ulcer[1] ? #0ebb23 : color.red)
signalColor = applyRibbonFilling ? trendColor : #1155cc

ulcerPlot = plot(ulcer, title="Ulcer", linewidth=2, color=ulcerColor, transp=0)
signalPlot = plot(showSignal ? signal : na, title="Signal", color=signalColor, transp=0)

ribbonFillColor = applyRibbonFilling ? trendColor : na
fill(ulcerPlot, signalPlot, title="Ribbon", color=ribbonFillColor, transp=70)

plotshape(crossover(ulcer, signal) and highlightCrossovers ? signal : na, title="Crossover", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(crossunder(ulcer, signal) and highlightCrossovers ? signal : na, title="Crossunder", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)

hline(breakout, title="Breakout Level", linestyle=hline.style_dotted, linewidth=2)
breakoutFillColor = ulcer > breakout ? #ff9800 : na
bgcolor(breakoutFillColor, transp=90)

Overview

Ulcer Index computes percentage drawdowns relative to the highest price, averages their squares, and takes the square root. An adjustable signal line using SMA or EMA tracks trend changes in volatility, with options to fill the ribbon between lines, highlight signal crossovers with shapes, and shade the background when the index exceeds a custom breakout threshold. Drawn in a separate pane.

Details

Published by

everget on GitHub

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinepinescripttechnical-indicatorsindicatorsoscillatorbandsaveragetradingviewindicatormoving-average

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Lengthint14length
Smoothing Lengthint14smoothLength
Breakout Levelfloat1.5breakout
Signal Smoothing TypestringSMAsignalType
Signal Smoothing Lengthint52signalLength
Sourcesourceclosesrc
Show Signal ?booltrueshowSignal
Highlight Signal Crossovers ?booltruehighlightCrossovers
Apply Ribbon Filling ?booltrueapplyRibbonFilling
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
330 stars

This indicator plots candle range and open-to-close movement as percentages in a separate pane. Range is the high-low difference divided by the low, and change is the close-open difference divided by the open. Both series draw as columns. Teal columns show ran

Indicator v5 Volatility & bands
Updated 2 months ago · None stated GitHub repository of Percent & Volatility [Alorse]

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers