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

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,



                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 cre8able, Today, 03:20 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post cre8able  
                  Started by Fran888, 02-16-2024, 10:48 AM
                  3 responses
                  47 views
                  0 likes
                  Last Post Sam2515
                  by Sam2515
                   
                  Started by martin70, 03-24-2023, 04:58 AM
                  15 responses
                  114 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by The_Sec, Today, 02:29 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  2 responses
                  32 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X