McClellan Oscillator & Summation Index

Modified on 2020/07/19 14:31 by Eugene — Categorized as: Community Indicators

McClellan Oscillator: Indicator Documentation

Syntax

public MCO(Bars advBars, Bars decBars, int period1, int period2, string description) public static MCO Series(Bars advBars, Bars decBars, int period1, int period2)

Parameter Description

advBarsThe Bars object for NYSE advancing issues
decBarsThe Bars object for NYSE declining issues
period1First EMA lookback period (19)
period2First EMA lookback period (39)

Description

According to definition at Investopedia, McClellan Oscillator is a market breadth indicator that is based on the difference between the number of advancing and declining issues on the NYSE.

References:


Example

This example illustrates how to plot McClellan Oscillator using Wealth-Data provider, as well as construct McClellan Summation Index:

using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Indicators;

namespace WealthLab.Strategies { public class MCO_demo : WealthScript { private StrategyParameter per1; private StrategyParameter per2; public MCO_demo() { per1 = CreateParameter("EMA Period 1",19,2,300,20); per2 = CreateParameter("EMA Period 2",39,2,300,20);

} protected override void Execute() { // NYSE Advancers and Decliners data using Wealth-Data provider Bars adv = GetExternalSymbol( "$NYSE_ADVN", true ); Bars dec = GetExternalSymbol( "$NYSE_DECLN", true ); DataSeries mco = MCO.Series(adv,dec,per1.ValueInt,per2.ValueInt);

ChartPane paneMCOPane2 = CreatePane(30,true,true); ChartPane paneMCOPane1 = CreatePane(30,true,true); PlotSeries(paneMCOPane1,mco,Color.FromArgb(255,0,0,255),LineStyle.Solid,1);

// McClellan Summation Index DataSeries mcoSumIdx = new DataSeries( Bars, "McClellan Summation Index" ); for(int bar = Math.Max(per2.ValueInt,per1.ValueInt); bar < Bars.Count; bar++) { if( adv.Closebar > 0 ) mcoSumIdxbar = mcoSumIdxbar-1 + mcobar; }

PlotSeriesOscillator(paneMCOPane2,mcoSumIdx,1000,-1000, Color.FromArgb( 30,Color.DarkBlue ),Color.FromArgb( 30,Color.DarkRed ),Color.Red,LineStyle.Solid,1); } } }


Alternative calculation of McClellan Summation Index based on James Miekka's formula. The traditional method (see code above) causes some undesired drift, and the Miekka formula stabilizes the Summation Index, preventing the drift, and allows to calculate it without knowing the prior day's value. Thanks Sammy_G!

using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { int per1 = 19; int per2 = 39; // NYSE Advancers and Decliners data using Wealth-Data provider Bars adv = GetExternalSymbol( "$NYSE_ADVN", true ); Bars dec = GetExternalSymbol( "$NYSE_DECLN", true ); DataSeries mco = MCO.Series(adv,dec,per1,per2); DataSeries mcoSumIdx_m = Close*0; mcoSumIdx_m.Description = "McClellan Summation Index (Miekka)"; DataSeries AminusD = adv.Close - dec.Close; DataSeries emaST = EMA.Series( AminusD, per1, EMACalculation.Modern ); DataSeries emaLT = EMA.Series( AminusD, per2, EMACalculation.Modern ); for(int bar = 3* Math.Max(per2,per1); bar < Bars.Count; bar++) { mcoSumIdx_mbar = 1000 - 9*emaSTbar + 19*emaLTbar; } ChartPane mcosi = CreatePane( 30, true,true); PlotSeries( mcosi, mcoSumIdx_m, Color.DarkGreen, WealthLab.LineStyle.Histogram, 3 ); } } }