• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

enumeration in multiple indicators

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

    enumeration in multiple indicators

    I created an indicator with enumeration values.

    I then created another indicator with the same indicator values and NT states it already exists.

    Is there a way to encapsulate the enumeration so it will ONLY stay within its own indicator

    #2
    Hello,

    Thank you for the post.

    Generally speaking, if two separate indicators have two separate enums they should be defined as separate names in case you are defining them outside of the indicators class. If you are defining them inside the class, it should not have problems seeing them in the same scope:

    Code:
    public class Test1 : Indicator
    {
    	public enum MyCustomEnum{
    	     one,two,three
    	}
    }
    In the case you are making two indicators that use the same enum, that enum should instead be defined in a separate file that is not an Indicator specifically. In this case, you could generate a new indicator and delete all the default code and replace it with the following to define your shared enum:

    MyEnum.cs inside of the Indicators folder.
    Code:
    namespace NinjaTrader.Indicator.MyEnumNamespace
    {
       public enum MyCustomEnum{
    	one,two,three
    	}
    }

    After doing this, both indicators can then use the enum while using the fully qualified name:


    Code:
    private NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum myEnumVariable;
    
    
    protected override Intialize()
    {
     myEnumVariable= NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum.one;
    }
    This would require that you select the file with the Enum defined in addition to your indicator when exporting, meaning you would export the indicator Test1 and the file containing the enum definition MyEnum.cs per the example.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      you can not initialize them in a class because nt can not find them

      Comment


        #4
        i tried to create an enum inside a class and it gives errors

        this is what i would have


        public class myPanel : Indicator
        {

        public enum eZigZagDeviation
        {
        POINTS,
        PERCENT
        }



        public eZigZagDeviation eZigZagType = eZigZagDeviation.POINTS;
        [Description("Pivot Type (Swing/ZigZag)")]
        [GridCategory("Pivot Type")]
        [Gui.Design.DisplayName("Pivot Type (Points/Percent)")]
        public eZigZagDeviation ZigZagType
        {
        get { return eZigZagType; }
        set { eZigZagType = value; }
        }


        if it is outside the indicator class it works
        Attached Files
        Last edited by ballboy11; 09-18-2017, 01:04 PM.

        Comment


          #5
          now I have a crazy issue this is what I have


          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;
          using System.Collections;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          using System.Windows.Forms;

          namespace NinjaTrader.Indicator
          {
          //

          public enum ePanelForZigZag
          {
          POINTS,
          PERCENT
          }



          //stufff


          #region Properties


          private ePanelForZigZag ePanelZigZagType = ePanelForZigZag.POINTS;
          [Description("Pivot Type (Swing/ZigZag)")]
          [GridCategory("Pivot Type")]
          [Gui.Design.DisplayName("Pivot Type (Points/Percent)")]
          public ePanelForZigZag PanelZigZagType
          {
          get { return ePanelZigZagType; }
          set { ePanelZigZagType = value; }

          }


          i add the enum no problem then i add the parameter i get an error
          Attached Files

          Comment


            #6
            Hello,

            Thank you for the reply.

            In this case, it looks like you have not copied the example I had provided exactly, you are not using the full namespace name when trying to access your enum.

            Because this is inside of the class, and NinjaTrader works differently than a standard C# application you would need to explicitly point to the enum everywhere you have used it. This is also the case when exporting scripts that use enums, the full name should always be used and using statements should be avoided.

            For your public property, it would look like the following:

            Code:
            private NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum myEnumVariable = NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum.one;
                   
            		
            [Description("Pivot Type (Swing/ZigZag)")]
            [GridCategory("Pivot Type")]
            [Gui.Design.DisplayName("Pivot Type (Points/Percent)")]
            public NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum MyEnumProperty
            {
            	get { return myEnumVariable; }
            	set { myEnumVariable = value; }
            }
            I would suggest reverting to a state where you can compile once again, and then retry using the previous example ensuring to use the full namespace name everywhere you use the enum: NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              creating enum in a seperate file

              I am having too many issues with my enum and I wil just place it in a seperate file now does nt7 and nt8 have differerent methods of creating a a seperate enum?

              Secondly how do I create an enum as a second file and acces this enum?

              I thought I had it working. It works in open source, it compiles as a dll but installation gives the error. stating enums don't exist so that is why I am going to create a seperate file and access the enum.

              Yes thats is exactly what I want to do is create an enum file for all my indicators
              Last edited by ballboy11; 09-20-2017, 06:13 AM.

              Comment


                #8
                Hello ballboy11,

                For an example of having an enum in one file and accessing it from another, I found a example at the following link,

                http://ninjatrader.com/support/forum...07&postcount=1

                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you I finally got it to work I created a enum indicator and it works great now.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by pjsmith, Today, 02:56 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post pjsmith
                  by pjsmith
                   
                  Started by ntbone, Yesterday, 08:10 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post ntbone
                  by ntbone
                   
                  Started by chrislou, 08-28-2015, 03:27 AM
                  14 responses
                  2,882 views
                  0 likes
                  Last Post nkhoi
                  by nkhoi
                   
                  Started by outofstock, Yesterday, 06:40 PM
                  2 responses
                  8 views
                  0 likes
                  Last Post outofstock  
                  Started by saeed, Yesterday, 12:32 PM
                  3 responses
                  41 views
                  0 likes
                  Last Post NinjaTrader_PatrickG  
                  Working...
                  X