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

Simple ATR w/ EMA Indicator

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

    Simple ATR w/ EMA Indicator

    I'm trying to plot an EMA on top of ATR and followed the "Indicator on Indicator" tutorial to the T (substituting ATR for Volume and EMA for SMA) but I get an error that says -

    Indicator\MyCustomIndicator.cs The parameter name 'period' is a duplicate

    I actually followed the tutorial exactly for Volume SMA without substituting ATR and EMA and got the same errors. Notice that the NinjaScript file its calling is "MyCustomIndicator" instead of "ATREMA". Could the problem be related to this? Aside from that, I'm stumped because I'm still very new at this. Here is my code -


    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// ATR with EMA plotted
        /// </summary>
        [Description("ATR with EMA plotted")]
        public class ATREMA : Indicator
        {
            #region Variables
            // Wizard generated variables
                private int period = 8; // Default setting for Period
            // 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(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                CalculateOnBarClose    = true;
                Overlay                = false;
                PriceTypeSupported    = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Calculate the ATR average
                double average = EMA(VOL(), Period)[0];
                // Set the calculated value to the plot
                Plot0.Set(average);
            }
    
            #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 Plot0
            {
                get { return Values[0]; }
            }
    
            [Description("Number of Periods")]
            [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
    {
        public partial class Indicator : IndicatorBase
        {
            private ATREMA[] cacheATREMA = null;
    
            private static ATREMA checkATREMA = new ATREMA();
    
            /// <summary>
            /// ATR with EMA plotted
            /// </summary>
            /// <returns></returns>
            public ATREMA ATREMA(int period)
            {
                return ATREMA(Input, period);
            }
    
            /// <summary>
            /// ATR with EMA plotted
            /// </summary>
            /// <returns></returns>
            public ATREMA ATREMA(Data.IDataSeries input, int period)
            {
                checkATREMA.Period = period;
                period = checkATREMA.Period;
    
                if (cacheATREMA != null)
                    for (int idx = 0; idx < cacheATREMA.Length; idx++)
                        if (cacheATREMA[idx].Period == period && cacheATREMA[idx].EqualsInput(input))
                            return cacheATREMA[idx];
    
                ATREMA indicator = new ATREMA();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                indicator.Input = input;
                indicator.Period = period;
                indicator.SetUp();
    
                ATREMA[] tmp = new ATREMA[cacheATREMA == null ? 1 : cacheATREMA.Length + 1];
                if (cacheATREMA != null)
                    cacheATREMA.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheATREMA = tmp;
                Indicators.Add(indicator);
    
                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>
            /// ATR with EMA plotted
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.ATREMA ATREMA(int period)
            {
                return _indicator.ATREMA(Input, period);
            }
    
            /// <summary>
            /// ATR with EMA plotted
            /// </summary>
            /// <returns></returns>
            public Indicator.ATREMA ATREMA(Data.IDataSeries input, int period)
            {
                return _indicator.ATREMA(input, period);
            }
    
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// ATR with EMA plotted
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.ATREMA ATREMA(int period)
            {
                return _indicator.ATREMA(Input, period);
            }
    
            /// <summary>
            /// ATR with EMA plotted
            /// </summary>
            /// <returns></returns>
            public Indicator.ATREMA ATREMA(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.ATREMA(input, period);
            }
    
        }
    }
    #endregion


    It is giving me the error in lines 140 and up, so in the portion that NinjaScript generates itself. Any help is greatly appreciated.
    Last edited by tmoose; 10-14-2008, 09:41 PM.

    #2
    Hi tmoose,

    When you compile any NinjaScript file it needs to compile the whole environment. Your error is not in your ATREMA indicator, but in your MyCustomIndicator. You will need to open that file up and address it there. Alternatively, you can just try deleting MyCustomIndicator if you do not want it anymore.
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Shansen, 08-30-2019, 10:18 PM
    24 responses
    938 views
    0 likes
    Last Post spwizard  
    Started by Max238, Today, 01:28 AM
    0 responses
    3 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by rocketman7, Today, 01:00 AM
    0 responses
    2 views
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    27 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Working...
    X