NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 10-14-2008, 09:32 PM   #1
tmoose
Junior Member
 
Join Date: Oct 2008
Posts: 3
Thanks: 0
Thanked 0 times in 0 posts
Default 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 at 09:41 PM.
tmoose is offline  
Reply With Quote
Old 10-15-2008, 08:21 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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.
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with simple indicator JT454 Indicator Development 7 10-07-2008 11:09 AM
Looking for someone to write a simple indicator for me pclark Indicator Development 2 09-06-2008 11:05 PM
Something Simple suburban General Programming 3 04-20-2008 12:40 AM
Help me fix my simple Line @ Bid Price Indicator NinjaCustomer Indicator Development 8 03-06-2008 10:06 AM
Simple Indicator Ronin General Programming 11 09-18-2007 08:30 AM


All times are GMT -6. The time now is 12:31 AM.