My coding runs into some recursive issue which I believe is beyond my knowledge to resolve.
The indicator of MA Envelopes runs well, but when I tried to code it into multiple time frame, this issue comes up.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Moving Average Envelopes
/// </summary>
[Description("Plots % envelopes around a moving average")]
public class Envelopes : Indicator
{
#region Variables
private int matype = 3;
private int period = 26;
private double envelopePercentage = 0.618;
private double innerPercentage = 0.381;
private int timeFrame =30;
#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()
{
// Adds a plot for the MA values to be stored in
Add(new Plot(Color.Gold, "Upper"));
Add(new Plot(Color.Red, "Middle"));
Add(new Plot(Color.Gold, "Lower"));
Add(new Plot(Color.Khaki, "InnerUpper"));
Add(new Plot(Color.Khaki, "InnerLower"));
Plots[1].Pen.DashStyle = DashStyle.Dash;
Add(PeriodType.Minute,timeFrame);
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
double maValue = 0;
switch (matype)
{
case 1:
{
Middle.Set(maValue = EMA(BarsArray[1], Period)[0]);
break;
}
case 2:
{
Middle.Set(maValue = HMA(BarsArray[1], Period)[0]);
break;
}
case 3:
{
Middle.Set(maValue = SMA(BarsArray[1], Period)[0]);
break;
}
case 4:
{
Middle.Set(maValue = TMA(BarsArray[1], Period)[0]);
break;
}
case 5:
{
Middle.Set(maValue = TEMA(BarsArray[1], Period)[0]);
break;
}
case 6:
{
Middle.Set(maValue = WMA(BarsArray[1], Period)[0]);
break;
}
}
Upper.Set(maValue + (maValue * EnvelopePercentage / 100));
Lower.Set(maValue - (maValue * EnvelopePercentage / 100));
InnerUpper.Set(maValue + (maValue*InnerPercentage/100));
InnerLower.Set(maValue - (maValue*InnerPercentage/100));
}
#region Properties
[Description("1 = EMA, 2 = HMA, 3 = SMA, 4= TMA, 5 = TEMA, 6 = WMA")]
[GridCategory("Parameters")]
[Gui.Design.DisplayNameAttribute("Moving average type")]
public int MAType
{
get { return matype; }
set { matype = Math.Min(6, Math.Max(1, value)); }
}
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
[Gui.Design.DisplayNameAttribute("Period")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
[Description("Percentage around MA that envelopes will be drawn")]
[GridCategory("Parameters")]
[Gui.Design.DisplayNameAttribute("Envelope percent offset")]
public double EnvelopePercentage
{
get { return envelopePercentage; }
set { envelopePercentage = Math.Max(0.01, value); }
}
[Description("Percentage around MA that envelopes will be drawn")]
[GridCategory("Parameters")]
[Gui.Design.DisplayNameAttribute("Envelope percent offset")]
public double InnerPercentage
{
get { return innerPercentage; }
set { innerPercentage = Math.Max(0.01, value); }
}
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
[Gui.Design.DisplayNameAttribute("timePeriod")]
public int timeFrame
{
get { return timeFrame; }
set { timeFrame= Math.Max(1, value); }
}
[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 Upper
{
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 Middle
{
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 Lower
{
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 InnerUpper
{
get { return Values[3]; }
}
[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 InnerLower
{
get { return Values[4]; }
}
#endregion
}
}
The notification is included in the attachment.
Thank you !!

Comment