Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

exponential moving average - initial period

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    exponential moving average - initial period

    When I tried the EMA indicator on a chart, I saw that the initial period were not display (which is what I want), i.e. if I do EMA(10), I don't want that indicator to display or use the initial 10 (or 9) periods.

    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;
    }
    }
    }
    }


    ------
    Last edited by uday12; 01-22-2016, 05:50 PM.

    #2
    Hello uday12,

    Thank you for writing in.

    The initial plots are removed from the chart due to the BarsRequired property, which defaults to 20 if not specified within the Initialize() method of the indicator.

    As the EMA indicator does not modify the BarsRequired property in Initialize(), the first 20 bars will not have the EMA plotted.

    This is NOT the same as a minimum number of bars required to calculate the indicator values; it merely prevents the indicator from plotting until the BarsRequired + 1 bar on the chart.

    For more information about BarsRequired, please take a look at this link: https://ninjatrader.com/support/help...rsrequired.htm

    The values are still calculated despite the plot not displaying on the chart unless code is specified to prevent calculating anything.

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X