McClellan Oscillator free

by qualitiedx2 in category Oscilator at 16/05/2012

The McClellan oscillator is a market breadth indicator used by financial analysts to evaluate the rate of money entering or leaving the market and interpretively indicate overbought or oversold conditions of the market.

Developed by Sherman and Marian McClellan in 1969, the oscillator is computed using the EMA of the daily ordinal difference of advancing issues (stocks which gained in value) from declining issues (stocks which fell in value) over 39 trading day and 19 trading day periods.

McClellan Oscillator

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class MSI : Indicator
        [Output("MSIupper", Color = Colors.Blue, IsHistogram = true)]
        public IndicatorDataSeries MSIup { get; set; }
        [Output("MSIupperLine", Color = Colors.Blue)]
        public IndicatorDataSeries MSIupline { get; set; }
        [Output("MSILower", Color = Colors.Red, IsHistogram = true)]
        public IndicatorDataSeries MSIlow { get; set; }
        [Output("MSILowerLine", Color = Colors.Red)]
        public IndicatorDataSeries MSIlowline { get; set; }

        [Parameter(DefaultValue = 39)]
        public int SlowPeriod { get; set; }

        [Parameter(DefaultValue = 19)]
        public int FastPeriod { get; set; }
        private ExponentialMovingAverage ema1;
        private ExponentialMovingAverage ema2;
		protected override void Initialize()
            ema1 = Indicators.ExponentialMovingAverage(MarketSeries.Close,SlowPeriod);
            ema2 = Indicators.ExponentialMovingAverage(MarketSeries.Close,FastPeriod);
        public override void Calculate(int index)
			double McClellanUpper = Math.Max(((ema2.Result[index]) - (ema1.Result[index])), 0);
     		double McClellanLower = Math.Min(((ema2.Result[index]) - (ema1.Result[index])), 0);
     		MSIup[index] = McClellanUpper;
     		MSIlow[index] = McClellanLower;
     		MSIlowline[index] = McClellanLower;