Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Another Enum discussion and Strategy problem

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

    Another Enum discussion and Strategy problem

    As I understand, enum should be placed in a namespace, but for me this is a problem because it doesn't allow versioning : different versions of an indy have to share the same enum, this is very strong coupling.

    So what I do is declare enums public in the indicator, so each indicator has its own enum, and no problem with versioning.

    In the properties, you have to prefix the type with NinjaTrader.Indicator.IndyName

    Example :
    Code:
        public class TestEnum : Indicator
        {     
            public enum Enum {One, Two, Three};
            private Enum myInput0 = Enum.One; 
    
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
            }
    
    
            protected override void OnBarUpdate()
            {
                Plot0.Set(Close[0]);
            }
    
    
            [Browsable(false)]    
            [XmlIgnore()]    
            public DataSeries Plot0
            {
                get { return Values[0]; }
            }
    
            
            [GridCategory("Parameters")]
            public NinjaTrader.Indicator.TestEnum.Enum MyInput0
            {
                get { return myInput0; }
                set { myInput0 = value; }
            }
        }
    Everything is OK, but there is a problem in the strategy wizard : the Wizard adds a + symbol, and the strategy won't compile.


    If strategy is unlocked, and '+' replaced with '.', compilation goes OK, but it's not possible to ask end users to do that.

    Any idea ?
    Attached Files

    #2
    Hi gomi, unfortunately we could only support enum use and setup as showcased in this example here - http://www.ninjatrader.com/support/f...ead.php?t=3420

    Used this way, the enum selection would word in the wizard interface as well.

    Comment


      #3
      Originally posted by gomifromparis View Post
      As I understand, enum should be placed in a namespace, but for me this is a problem because it doesn't allow versioning : different versions of an indy have to share the same enum, this is very strong coupling.

      So what I do is declare enums public in the indicator, so each indicator has its own enum, and no problem with versioning.

      In the properties, you have to prefix the type with NinjaTrader.Indicator.IndyName

      Example :
      Code:
          public class TestEnum : Indicator
          {     
              public enum Enum {One, Two, Three};
              private Enum myInput0 = Enum.One; 
      
              protected override void Initialize()
              {
                  Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
              }
      
      
              protected override void OnBarUpdate()
              {
                  Plot0.Set(Close[0]);
              }
      
      
              [Browsable(false)]    
              [XmlIgnore()]    
              public DataSeries Plot0
              {
                  get { return Values[0]; }
              }
      
              
              [GridCategory("Parameters")]
              public NinjaTrader.Indicator.TestEnum.Enum MyInput0
              {
                  get { return myInput0; }
                  set { myInput0 = value; }
              }
          }
      Everything is OK, but there is a problem in the strategy wizard : the Wizard adds a + symbol, and the strategy won't compile.


      If strategy is unlocked, and '+' replaced with '.', compilation goes OK, but it's not possible to ask end users to do that.

      Any idea ?
      That is because you are declaring the enum inside a class. What you want to do is to either follow the NT official position and pollute the global namespace, with all its problems that we have spoken about ad nauseam to no avail; or else obey Progamming101 and truly create a separate namespace within the files and use it. I show how in this link to an answer that I provided a while back: http://www.ninjatrader.com/support/f...16047#poststop

      Comment


        #4
        Yes, that's what I finally used. I liked the idea of the indicator carrying its own enum, though, but the Strategy Wizard doesn't like it.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        331 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        549 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        550 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X