Category Volatility  Published on 08/12/2021

Ulcer Index

Description

Developed by Peter Martin and Byron McCann in 1987, the Ulcer Index is a volatility indicator that measures downside risk. It was first introduced in their 1989 book, The Investor's Guide to Fidelity Funds. Originally, the index was designed with mutual funds in mind, which is why it is only focused on downside risk. Mutual funds are designed to make money by increasing in value; the only risk, therefore, is the drawdown or downside. As its name implies, the Ulcer Index measures the drawdown investors can expect to stomach on any given security. Many consider the Ulcer Index superior to the standard deviation and other measures of risk.

 

Github: GitHub - Doustzadeh/cTrader-Indicator

 


using System;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class UlcerIndex : Indicator
    {
        // Percent-Drawdown = ((Close - 14-period Max Close) / 14-period Max Close) x 100
        // Squared Average = (14-period Sum of Percent-Drawdown Squared) / 14 
        // Ulcer Index = Square Root of Squared Average

        [Parameter("Periods", DefaultValue = 14)]
        public int Periods { get; set; }

        [Output("Ulcer Index", LineColor = "Red")]
        public IndicatorDataSeries Result { get; set; }

        private IndicatorDataSeries PercentDrawdown, PercentDrawdownSquared;

        protected override void Initialize()
        {
            PercentDrawdown = CreateDataSeries();
            PercentDrawdownSquared = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            PercentDrawdown[index] = ((Bars.ClosePrices[index] - Bars.ClosePrices.Maximum(Periods)) / Bars.ClosePrices.Maximum(Periods)) * 100;
            PercentDrawdownSquared[index] = Math.Pow(PercentDrawdown[index], 2);
            double SquaredAverage = PercentDrawdownSquared.Sum(Periods) / Periods;
            Result[index] = Math.Sqrt(SquaredAverage);
        }
    }
}


Doustzadeh's avatar
Doustzadeh

Joined on 20.03.2016

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Ulcer Index.algo
  • Rating: 0
  • Installs: 903
Comments
Log in to add a comment.
No comments found.