Anyhow, this is a skeleton of how I would go about it. You will have to fill out the parts where I have indicated some etc stuff, but at least the first 2 Plots show up, if you use any of the valid defined MA's (the only valid ones I used are SMA, EMA and WMA). It is just a demo, which you will have to expand to your 17 types, but the entire skeleton is exposed.
Have fun!
//this goes outside the class. Best to put it right under the "using declarations" region, right at the top of the file: using CheechGazillions; namespace CheechGazillions { public enum MAType { SMA, EMA, WMA, Type1, Type2, Type3 //etc } }
#region Variables //define periods for MA's private int mA1Period = 5; private int mA2Period = 8; private int mA3Period = 13; private int mA4Period = 21; //defaults for MATypes private MAType mA1Type = MAType.SMA; private MAType mA2Type = MAType.SMA; private MAType mA3Type = MAType.SMA; private MAType mA4Type = MAType.SMA; //define named instances for each of the MA's as wach type private SMA mA1SMA; private EMA mA1EMA; private WMA mA1WMA; // etc for each MAType private SMA mA2SMA; private EMA mA2EMA; private WMA mA2WMA; // etc for each MAType private SMA mA3SMA; private EMA mA3EMA; private WMA mA3WMA; // etc for each MAType private SMA mA4SMA; private EMA mA4EMA; private WMA mA4WMA; // etc for each MAType #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Square, "Plot0")); Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Square, "Plot1")); Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Square, "Plot2")); Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Square, "Plot3")); Overlay = true; } protected override void OnStartUp() { switch (mA1Type) { case MAType.WMA: this.DisposeAllMA1(); this.mA1WMA = WMA(Input, this.mA1Period); break; case MAType.EMA: this.DisposeAllMA1(); this.mA1EMA = EMA(Input, this.mA1Period); break; case MAType.Type1: // you need to put the correct stuff here, using the //same syntax style for Type1, which in this sample //has not been defined. Look at the EMA etc examples. break; //etc for the rest of the 17 types default: case MAType.SMA: this.DisposeAllMA1(); this.mA1SMA = SMA(Input, this.mA1Period); break; } //repeat the switch structure for mA2Type, mA3Type and mA4Type switch (mA2Type) { case MAType.WMA: this.DisposeAllMA2(); this.mA2WMA = WMA(Input, this.mA2Period); break; case MAType.EMA: this.DisposeAllMA2(); this.mA2EMA = EMA(Input, this.mA2Period); break; case MAType.Type1: // you need to put the correct stuff here, usig the //same syntax style for Type1, which in this sample //has not been defined. Look at the EMA etc examples. break; //etc for the rest of the 17 types default: case MAType.SMA: this.DisposeAllMA2(); this.mA2SMA = SMA(Input, this.mA2Period); break; } //etc } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < this.BarsRequired) return; switch (mA1Type) { case MAType.WMA: Plot0.Set(this.mA1WMA[0]); break; case MAType.EMA: Plot0.Set(this.mA1EMA[0]); break; case MAType.Type1: // you need to put the correct stuff here, using the //same syntax style for Type1, which in this sample //has not been defined. Look at the EMA etc examples. break; //etc for the rest of the 17 types default: case MAType.SMA: Plot0.Set(this.mA1SMA[0]); break; } //repeat the switch structure for mA2Type(Plot1)), mA3Type(Plot2) and mA4Type(Plot3) switch (mA2Type) { case MAType.WMA: Plot1.Set(this.mA2WMA[0]); break; case MAType.EMA: Plot1.Set(this.mA2EMA[0]); break; case MAType.Type1: // you need to put the correct stuff here, using the //same syntax style for Type1, which in this sample //has not been defined. Look at the EMA etc examples. break; //etc for the rest of the 17 types default: case MAType.SMA: Plot1.Set(this.mA2SMA[0]); break; } //etc //You now have all Plots set. The rest is just using those Plots, to examine x-overs etc.. } #region Functions private void DisposeAllMA1() { if (this.mA1SMA != null) this.mA1SMA.Dispose(); if (this.mA1EMA != null) this.mA1EMA.Dispose(); if (this.mA1WMA != null) this.mA1WMA.Dispose(); //etc for the rest of the 17 MATypes return; } private void DisposeAllMA2() { if (this.mA2SMA != null) this.mA2SMA.Dispose(); if (this.mA3EMA != null) this.mA3EMA.Dispose(); if (this.mA4WMA != null) this.mA4WMA.Dispose(); //etc for the rest of the 17 MATypes return; } //repeat for MA3 and MA4 #endregion #region Properties [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot0 { get { return Values[0]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot1 { get { return Values[1]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot2 { get { return Values[2]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Plot3 { get { return Values[3]; } } [Description("")] [GridCategory("Parameters")] public int MA1Period { get { return this.mA1Period; } set { this.mA1Period = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int MA2Period { get { return this.mA2Period; } set { this.mA2Period = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int MA3Period { get { return this.mA3Period; } set { this.mA3Period = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int MA4Period { get { return this.mA4Period; } set { this.mA4Period = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public MAType MA1Type { get { return this.mA1Type; } set { this.mA1Type = value; } } [Description("")] [GridCategory("Parameters")] public MAType MA2Type { get { return this.mA2Type; } set { this.mA2Type = value; } } [Description("")] [GridCategory("Parameters")] public MAType MA3Type { get { return this.mA3Type; } set { this.mA3Type = value; } } [Description("")] [GridCategory("Parameters")] public MAType MA4Type { get { return this.mA4Type; } set { this.mA4Type = value; } } #endregion
Comment