Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 cmtjoancolmenero, Yesterday, 03:58 PM
    1 response
    17 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by benmarkal, Yesterday, 12:52 PM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by helpwanted, Today, 03:06 AM
    1 response
    20 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    12 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    244 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Working...
    X