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

What does this code mean in lay mans term?

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

    What does this code mean in lay mans term?

    Hello,

    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

    #2
    Google EMA Envelopes

    Comment


      #3
      Agassi,

      Thank you for your post.

      Sledge's post is a good explanation and purpose of what the EMA Envelope will do.

      Let us know if we can be of further assistance.
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Thanks for the reply. Can an envelop be created in NT without having to write code? i.e. just like i would create any simple moving average? or do i have to write code to create an EMA envelop?

        Comment


          #5
          Originally posted by agassi View Post
          Thanks for the reply. Can an envelop be created in NT without having to write code? i.e. just like i would create any simple moving average? or do i have to write code to create an EMA envelop?
          What you have there is code? Does it not work? Where did you get it?

          There is already a MAEnvelope indicator in NT and it handles several types of moving averages.

          Comment


            #6
            I don't know where I downloaded it. Where can I get that MAE Envelope indicator that you are talking about? I want to to be able to configure it according to my needs. I am also trying to understand the business logic of this code.

            Thanks again.

            Comment


              #7
              Originally posted by agassi View Post
              I don't know where I downloaded it. Where can I get that MAE Envelope indicator that you are talking about? I want to to be able to configure it according to my needs. I am also trying to understand the business logic of this code.

              Thanks again.
              Which version of NT are you using? The one without the code editor? The really basic one? (I'm not sure what our is called).

              It sounds like you are missing some stuff and that might explain this.

              But in your chart if you add the NT supplied MAEnvelope indicator it should do what you want.

              Comment


                #8
                I have a full lifetime license. I am using NT 7.0.1000.25

                Comment


                  #9
                  Found it. Thanks. Now next question is, how to configure it so that it matches the code that I have shown here? That's all i am trying to do.

                  When I plot it, it is similar but the bands are too fat. Based on the code i think inputs are 2.00 and default was 1.5. But what about others? look back period? EWA of what? etc.

                  Comment


                    #10
                    I'll have to look on my machine later. On my cell now.

                    Comment


                      #11
                      agassi, looks like you want the type 1 (for the EMA) with a period of 96.

                      Your old channel does the offset in ticks from the center, while the NT Envelope indicator you were pointed to would do % wise.

                      So best would be some experimentation to see what settings you want to use.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        OK. Thanks. Let me play with it this weekend and update you.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NRITV, Today, 01:15 PM
                        2 responses
                        6 views
                        0 likes
                        Last Post NRITV
                        by NRITV
                         
                        Started by frankthearm, Today, 09:08 AM
                        7 responses
                        31 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by maybeimnotrader, Yesterday, 05:46 PM
                        5 responses
                        25 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by quantismo, Yesterday, 05:13 PM
                        2 responses
                        19 views
                        0 likes
                        Last Post quantismo  
                        Started by adeelshahzad, Today, 03:54 AM
                        5 responses
                        33 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Working...
                        X