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

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.
    BertrandNinjaTrader Customer Service

    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 PaulMohn, Today, 03:49 AM
        0 responses
        3 views
        0 likes
        Last Post PaulMohn  
        Started by inanazsocial, Today, 01:15 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by rocketman7, Today, 02:12 AM
        0 responses
        10 views
        0 likes
        Last Post rocketman7  
        Started by dustydbayer, Today, 01:59 AM
        0 responses
        2 views
        0 likes
        Last Post dustydbayer  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        23 views
        0 likes
        Last Post trilliantrader  
        Working...
        X