• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 NT-Roland, Today, 04:36 PM
    0 responses
    2 views
    0 likes
    Last Post NT-Roland  
    Started by Newtrader101, Today, 03:40 PM
    2 responses
    10 views
    0 likes
    Last Post Newtrader101  
    Started by Branpo, Today, 02:58 PM
    2 responses
    7 views
    0 likes
    Last Post Branpo
    by Branpo
     
    Started by sdauteuil, Today, 02:09 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by AMATX, Today, 02:19 PM
    2 responses
    11 views
    0 likes
    Last Post AMATX
    by AMATX
     
    Working...
    X