When I took at look at the main EMA code, I didn't find any place that removes the initial part:
------
namespace NinjaTrader.Indicator
{
[Description("The Exponential Moving Average is an indicator that ...")]
public class EMA : Indicator
{
#region Variables
private int period = 14;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.Orange, "EMA"));
Overlay = true;
}
protected override void OnBarUpdate()
{
Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);
}
#region Properties
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
#endregion
}
}
------
(a) Is the initial removal of the EMA indicator handled by the NinjaScript generated code part below ?? and if so, which section of this code does that?
(b) Also, when I call EMA from another indicator's code, do the values of EMA include the calculated values in the initial part (or do they drop it)?
------
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private EMA[] cacheEMA = null;
private static EMA checkEMA = new EMA();
public EMA EMA(int period)
{
return EMA(Input, period);
}
public EMA EMA(Data.IDataSeries input, int period)
{
if (cacheEMA != null)
for (int idx = 0; idx < cacheEMA.Length; idx++)
if (cacheEMA[idx].Period == period && cacheEMA[idx].EqualsInput(input))
return cacheEMA[idx];
lock (checkEMA)
{
checkEMA.Period = period;
period = checkEMA.Period;
if (cacheEMA != null)
for (int idx = 0; idx < cacheEMA.Length; idx++)
if (cacheEMA[idx].Period == period && cacheEMA[idx].EqualsInput(input))
return cacheEMA[idx];
EMA indicator = new EMA();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Period = period;
Indicators.Add(indicator);
indicator.SetUp();
EMA[] tmp = new EMA[cacheEMA == null ? 1 : cacheEMA.Length + 1];
if (cacheEMA != null)
cacheEMA.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheEMA = tmp;
return indicator;
}
}
}
}
------
Comment