I have this indicator and trying to figure out what it is. I am not a coder or developer. So can some one explain in simple lay mans term? This is some sort of an EMA and the inputs are configurable. Visually it looks very similar to a Bollinger Band i.e. there is an upper band, lower band and a middle band.
Here is the code:
This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class EmaEnvelope : Indicator
{
#region Variables
// Wizard generated variables
private int eMA_Period = 96; // Default setting for EMA_Period
private int eMA_Envelope = 11; // Default setting for EMA_Envelope
private bool reColorBars = false;
// User defined variables (add any user defined variables below)
#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(new Pen(Color.RoyalBlue, 2), PlotStyle.Line, "Upper"));
Add(new Plot(new Pen(Color.Orchid, 2), PlotStyle.Line, "Ema"));
Add(new Plot(new Pen(Color.RoyalBlue, 2), PlotStyle.Line, "Lower"));
Overlay = true;
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);
if (CurrentBar == 0)
{
Ema.Set(Input[0]);
}
else
{
Ema.Set(Input[0] * (2.0 / (1 + EMA_Period)) + (1 - (2.0 / (1 + EMA_Period))) * Ema[1]);
}
Upper.Set(Ema[0] + (EMA_Envelope * TickSize));
Lower.Set(Ema[0] - (EMA_Envelope * TickSize));
if (ReColorBars)
{
if (High[0] > Ema[0] && Low[0] > Ema[0])
BarColor = Color.Blue;
else if (High[0] < Ema[0] && Low[0] < Ema[0])
BarColor = Color.Red;
else
BarColor = Color.DarkGray;
}
}
#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 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 Ema
{
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]; }
}
[Description("")]
[GridCategory("Parameters")]
public int EMA_Period
{
get { return eMA_Period; }
set { eMA_Period = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int EMA_Envelope
{
get { return eMA_Envelope; }
set { eMA_Envelope = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool ReColorBars
{
get { return reColorBars; }
set { reColorBars = (value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private EmaEnvelope[] cacheEmaEnvelope = null;
private static EmaEnvelope checkEmaEnvelope = new EmaEnvelope();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public EmaEnvelope EmaEnvelope(int eMA_Envelope, int eMA_Period, bool reColorBars)
{
return EmaEnvelope(Input, eMA_Envelope, eMA_Period, reColorBars);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public EmaEnvelope EmaEnvelope(Data.IDataSeries input, int eMA_Envelope, int eMA_Period, bool reColorBars)
{
if (cacheEmaEnvelope != null)
for (int idx = 0; idx < cacheEmaEnvelope.Length; idx++)
if (cacheEmaEnvelope[idx].EMA_Envelope == eMA_Envelope && cacheEmaEnvelope[idx].EMA_Period == eMA_Period && cacheEmaEnvelope[idx].ReColorBars == reColorBars && cacheEmaEnvelope[idx].EqualsInput(input))
return cacheEmaEnvelope[idx];
lock (checkEmaEnvelope)
{
checkEmaEnvelope.EMA_Envelope = eMA_Envelope;
eMA_Envelope = checkEmaEnvelope.EMA_Envelope;
checkEmaEnvelope.EMA_Period = eMA_Period;
eMA_Period = checkEmaEnvelope.EMA_Period;
checkEmaEnvelope.ReColorBars = reColorBars;
reColorBars = checkEmaEnvelope.ReColorBars;
if (cacheEmaEnvelope != null)
for (int idx = 0; idx < cacheEmaEnvelope.Length; idx++)
if (cacheEmaEnvelope[idx].EMA_Envelope == eMA_Envelope && cacheEmaEnvelope[idx].EMA_Period == eMA_Period && cacheEmaEnvelope[idx].ReColorBars == reColorBars && cacheEmaEnvelope[idx].EqualsInput(input))
return cacheEmaEnvelope[idx];
EmaEnvelope indicator = new EmaEnvelope();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.EMA_Envelope = eMA_Envelope;
indicator.EMA_Period = eMA_Period;
indicator.ReColorBars = reColorBars;
Indicators.Add(indicator);
indicator.SetUp();
EmaEnvelope[] tmp = new EmaEnvelope[cacheEmaEnvelope == null ? 1 : cacheEmaEnvelope.Length + 1];
if (cacheEmaEnvelope != null)
cacheEmaEnvelope.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheEmaEnvelope = tmp;
return indicator;
}
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.EmaEnvelope EmaEnvelope(int eMA_Envelope, int eMA_Period, bool reColorBars)
{
return _indicator.EmaEnvelope(Input, eMA_Envelope, eMA_Period, reColorBars);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.EmaEnvelope EmaEnvelope(Data.IDataSeries input, int eMA_Envelope, int eMA_Period, bool reColorBars)
{
return _indicator.EmaEnvelope(input, eMA_Envelope, eMA_Period, reColorBars);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.EmaEnvelope EmaEnvelope(int eMA_Envelope, int eMA_Period, bool reColorBars)
{
return _indicator.EmaEnvelope(Input, eMA_Envelope, eMA_Period, reColorBars);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.EmaEnvelope EmaEnvelope(Data.IDataSeries input, int eMA_Envelope, int eMA_Period, bool reColorBars)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.EmaEnvelope(input, eMA_Envelope, eMA_Period, reColorBars);
}
}
}
#endregion
Comment