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

EMA plus

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

    EMA plus

    Hi ,
    I would like to create a 21 period EMA plus 20 cents . I see the regular EMA
    in the Edit Ninja script box . Could I just copy that into a new script box and
    add 20 cents some how ? tia .

    #2
    Yes, you can save it as a new file, and just add the 0.20 to the ema.

    Originally posted by T2020 View Post
    Hi ,
    I would like to create a 21 period EMA plus 20 cents . I see the regular EMA
    in the Edit Ninja script box . Could I just copy that into a new script box and
    add 20 cents some how ? tia .

    Comment


      #3
      When you save it, open up the EMA, right click and select "Save As..." provide a new name. This will do some stuff to make the duplication easy for you.
      RayNinjaTrader Customer Service

      Comment


        #4
        So you copy this whole thing ? And paste it into "My custom indicator " ?
        Where do you add the 20 cents ?
        __________________________________________________ _________
        //
        // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
        // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
        //

        #region Using declarations
        using System;
        using System.Diagnostics;
        using System.Drawing;
        using System.Drawing.Drawing2D;
        using System.ComponentModel;
        using System.Xml.Serialization;
        using NinjaTrader.Data;
        using NinjaTrader.Gui.Chart;
        #endregion

        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        /// <summary>
        /// Exponential Moving Average. The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        /// </summary>
        [Description("The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.")]
        public class EMA : Indicator
        {
        #region Variables
        private int period = 14;
        #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(Color.Orange, "EMA"));

        Overlay = true;
        PriceTypeSupported = true;
        }

        /// <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]);
        }

        #region Properties
        /// <summary>
        /// </summary>
        [Description("Numbers of bars used for calculations")]
        [Category("Parameters")]
        public int Period
        {
        get { return period; }
        set { period = Math.Max(1, 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
        {
        /// <summary>
        /// </summary>
        public partial class Indicator : IndicatorBase
        {
        private EMA[] cacheEMA = null;
        private static EMA checkEMA = new EMA();

        /// <summary>
        /// The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        /// </summary>
        /// <returns></returns>
        public EMA EMA(int period)
        {
        return EMA(Input, period);
        }

        /// <summary>
        /// The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        /// </summary>
        /// <returns></returns>
        public EMA EMA(Data.IDataSeries input, int period)
        {
        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;
        indicator.Input = input;
        indicator.Period = period;
        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;
        Indicators.Add(indicator);

        return indicator;
        }
        }
        }

        // This namespace holds all market analyzer column definitions and is required. Do not change it.
        namespace NinjaTrader.MarketAnalyzer
        {
        /// <summary>
        /// </summary>
        public partial class Column : ColumnBase
        {
        /// <summary>
        /// The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.EMA EMA(int period)
        {
        return _indicator.EMA(Input, period);
        }

        /// <summary>
        /// The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        /// </summary>
        /// <returns></returns>
        public Indicator.EMA EMA(Data.IDataSeries input, int period)
        {
        return _indicator.EMA(input, period);
        }
        }
        }

        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
        /// <summary>
        /// </summary>
        public partial class Strategy : StrategyBase
        {
        /// <summary>
        /// The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.EMA EMA(int period)
        {
        return _indicator.EMA(Input, period);
        }

        /// <summary>
        /// The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        /// </summary>
        /// <returns></returns>
        public Indicator.EMA EMA(Data.IDataSeries input, int period)
        {
        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.EMA(input, period);
        }
        }
        }
        #endregion
        _____________________________
        thx

        Comment


          #5
          T2020,

          You don't need to copy paste anything. Open up the NinjaScript Editor for EMA. Right click anywhere in the Editor window and select "Save As". Type a new name and your new indicator will be ready for you to go.

          The line you want to add the 20 cents to is here:
          Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);

          into something like this

          Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1] + 20 * TickSize);
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Thanks Josh ,
            I did as you said ,but don't see the indicator listed anywhere . So I can't add
            it to a chart . When I changed the name ,it said to make sure and change it
            some place else as well . Not sure about that .? Need a tad more help . thx.

            Comment


              #7
              Originally posted by T2020 View Post
              Thanks Josh ,
              I did as you said ,but don't see the indicator listed anywhere . So I can't add
              it to a chart . When I changed the name ,it said to make sure and change it
              some place else as well . Not sure about that .? Need a tad more help . thx.
              Anybody ? Sure I'm missing something simple ,but it isn't working so far .

              Comment


                #8
                Originally posted by T2020 View Post
                Anybody ? Sure I'm missing something simple ,but it isn't working so far .
                So just to make sure we are on the same page,

                (1) You did a "save as..." with a new filename.
                (2) Hit the compile button and the indicator complied without an error
                (3) Went to a chart and tried to add the indicator, but you did not see the name that you used in the "save as..."

                Is that what you did ?

                Comment


                  #9
                  Originally posted by twtrader View Post
                  So just to make sure we are on the same page,

                  (1) You did a "save as..." with a new filename.
                  (2) Hit the compile button and the indicator complied without an error
                  (3) Went to a chart and tried to add the indicator, but you did not see the name that you used in the "save as..."

                  Is that what you did ?
                  Didn't know about the compiling . And the word " ticksize " doesn't work . tried
                  something else and now I've got it working .
                  Thank you much for the help .
                  Last edited by T2020; 07-10-2008, 08:17 PM.

                  Comment


                    #10
                    No problem,

                    Indicators are compiled in NT, so when you are writing them, you have to compile them first.



                    Originally posted by T2020 View Post
                    Didn't know about the compiling . And the word " ticksize " doesn't work . tried
                    something else and now I've got it working .
                    Thank you much for the help .

                    Comment


                      #11
                      It is case sensitive. It is "TickSize" not "ticksize".
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by Josh View Post
                        It is case sensitive. It is "TickSize" not "ticksize".
                        I see ,thanks for clearing that up . I just put + 0.02 , which on the mini Russel seems to give me the 20 cents / 2 ticks I was looking for . thx

                        Comment


                          #13
                          Originally posted by Josh View Post
                          T2020,

                          You don't need to copy paste anything. Open up the NinjaScript Editor for EMA. Right click anywhere in the Editor window and select "Save As". Type a new name and your new indicator will be ready for you to go.

                          The line you want to add the 20 cents to is here:
                          Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);

                          into something like this

                          Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1] + 20 * TickSize);
                          I was just wondering if there was a word that I could substitute for (+ 20 * TickSize) or the ( 0.02 )that I'm using now , to make the indicator adjustable once it's on the chart . I may want to add this to a larger time
                          frame and adjust the distance amount accordingly . thx

                          Comment


                            #14
                            Sure, you can create a user defined input (property) that represents the "20".

                            Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1] + userDefinedInput * TickSize);

                            See here - http://www.ninjatrader-support.com/v...ead.php?t=5782
                            RayNinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Ray View Post
                              Sure, you can create a user defined input (property) that represents the "20".

                              Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1] + userDefinedInput * TickSize);

                              See here - http://www.ninjatrader-support.com/v...ead.php?t=5782
                              I get an error when I try this . "the name userDefinedInput does not exist
                              in this context " .. ???

                              Never mind , I see there's a ton of code to add which I don' understand .
                              Last edited by T2020; 07-11-2008, 11:46 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by alifarahani, Today, 09:40 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by RookieTrader, Today, 09:37 AM
                              4 responses
                              18 views
                              0 likes
                              Last Post RookieTrader  
                              Started by PaulMohn, Today, 12:36 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post PaulMohn  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              40 views
                              0 likes
                              Last Post love2code2trade  
                              Started by junkone, Today, 11:37 AM
                              3 responses
                              26 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X