Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

[NinjaScriptProperty] attribute

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

    [NinjaScriptProperty] attribute

    What does the [NinjaScriptProperty] attribute do?

    Thanks,
    EV

    #2
    Originally posted by ETFVoyageur View Post
    What does the [NinjaScriptProperty] attribute do?

    Thanks,
    EV
    Makes the property visible to the instance constructor, and enforces its use.

    Comment


      #3
      Originally posted by koganam View Post
      Makes the property visible to the instance constructor, and enforces its use.
      I have tried properties with and without that attribute. So far I see no difference. How do I see whatever different behavior its presence / absence causes?

      --EV

      Comment


        #4
        Originally posted by ETFVoyageur View Post
        I have tried properties with and without that attribute. So far I see no difference. How do I see whatever different behavior its presence / absence causes?

        --EV
        ref: http://ninjatrader.com/support/forum...66&postcount=5

        Of course, I know you will read the entire thread for context.

        You should also see it if you try to create a named instance of your indicator in another class. The constructor will enforce it, and show you so in Intellisense.

        Comment


          #5
          Originally posted by koganam View Post
          ref: http://ninjatrader.com/support/forum...66&postcount=5

          Of course, I know you will read the entire thread for context.

          You should also see it if you try to create a named instance of your indicator in another class. The constructor will enforce it, and show you so in Intellisense.
          Thanks .
          Last edited by ETFVoyageur; 08-03-2015, 01:12 PM.

          Comment


            #6
            I guess the attribute use is self-evident once you think about it. It appears to me that [NinjaScriptProperty] means "this property can be used from NinjaScript". Is that right? It is unrelated to GUI use (e.g. Indicators dialog) but could be used to enable/disable access to that property from NinjaScript (not that I have a use case for disabling such access).

            Adding [NinjaScriptProperty] to an enum property seems to be causing a problem with the Magic Code, though. When I added the attribute, I got a compiler error
            The type or namespace name 'DemoEnum' could not be found (are you missing a using directive or an assembly reference?)
            The error message refers to a Magic Code line
            Code:
                    public VsaModelIndicator VsaModelIndicator(DemoEnum demoEnumProperty, string stringProperty, int length, double height, bool enableDisableProperty, bool onOffProperty, bool yesNoProperty, xxxEnum xxxProperty)
            Here is my code that triggers the error message. Removing [NinjaScriptProperty] avoids the error (because the Magic Code no longer tries to use it) but that is presumably undesirable.
            Code:
                    public enum DemoEnum {
                        [EnumDisplayName("User-friendly label for Value 1")]        value1,
                        [EnumDisplayName("User-friendly label for Value 2")]        value2
                    }
                    private DemoEnum demoEnumProperty = DemoEnum.value2;
                    // Either of the following two forms of the [DefaultValue] attribute work -- choice is just personal style
                        [DefaultValue(DemoEnum.value2)]
                        //[DefaultValue(typeof(DemoEnum), "value2")]
                    [TypeConverter(typeof(EnumDescriptionConverter))]
                    [ReadOnly(false)]                                // Do allow the user to change the value
                    [Browsable(true)]                               // Do show in the indicator property dialog
                    [NinjaScriptProperty]                            // So the property can be used from NinjaScript, such as in a Strategy
                    [Display(Order = 0, Name = "User-friendly enum property", GroupName = demoCategory,
                            Description = "This property demonstrates an enum property using user-friendly labels")]
                    public DemoEnum DemoEnumProperty
                    {
                        get { return demoEnumProperty; }
                        set { demoEnumProperty = value; }
                    }
            Am I doing something wrong, or is this a bug in the generation of the Magic Code? Surely others have enum properties that work with the [NinjascriptProperty] attribute?

            (By the way, this is an example of a property where the type conversion works in NT 7, but not in NT 8.)

            --EV
            Last edited by ETFVoyageur; 08-03-2015, 01:54 PM.

            Comment


              #7
              Originally posted by ETFVoyageur View Post
              Adding [NinjaScriptProperty] to an enum property seems to be causing a problem with the Magic Code, though. When I added the attribute, I got a compiler error.
              I initially struggle a bit with this myself.. I created this to test a public enum in an exported dll.. Just a simple modification to the SampleUniversalMovingAverage.. What I found strange was creating the enum outside both the indicator class and namespace.. (but it does seem to work)..


              Attached Files
              -=Edge=-
              NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

              Comment


                #8
                Originally posted by ETFVoyageur View Post
                I guess the attribute use is self-evident once you think about it. It appears to me that [NinjaScriptProperty] means "this property can be used from NinjaScript". Is that right? It is unrelated to GUI use (e.g. Indicators dialog) but could be used to enable/disable access to that property from NinjaScript (not that I have a use case for disabling such access).

                Adding [NinjaScriptProperty] to an enum property seems to be causing a problem with the Magic Code, though. When I added the attribute, I got a compiler error The error message refers to a Magic Code line
                Code:
                        public VsaModelIndicator VsaModelIndicator(DemoEnum demoEnumProperty, string stringProperty, int length, double height, bool enableDisableProperty, bool onOffProperty, bool yesNoProperty, xxxEnum xxxProperty)
                Here is my code that triggers the error message. Removing [NinjaScriptProperty] avoids the error (because the Magic Code no longer tries to use it) but that is presumably undesirable.
                Code:
                        public enum DemoEnum {
                            [EnumDisplayName("User-friendly label for Value 1")]        value1,
                            [EnumDisplayName("User-friendly label for Value 2")]        value2
                        }
                        private DemoEnum demoEnumProperty = DemoEnum.value2;
                        // Either of the following two forms of the [DefaultValue] attribute work -- choice is just personal style
                            [DefaultValue(DemoEnum.value2)]
                            //[DefaultValue(typeof(DemoEnum), "value2")]
                        [TypeConverter(typeof(EnumDescriptionConverter))]
                        [ReadOnly(false)]                                // Do allow the user to change the value
                        [Browsable(true)]                               // Do show in the indicator property dialog
                        [NinjaScriptProperty]                            // So the property can be used from NinjaScript, such as in a Strategy
                        [Display(Order = 0, Name = "User-friendly enum property", GroupName = demoCategory,
                                Description = "This property demonstrates an enum property using user-friendly labels")]
                        public DemoEnum DemoEnumProperty
                        {
                            get { return demoEnumProperty; }
                            set { demoEnumProperty = value; }
                        }
                Am I doing something wrong, or is this a bug in the generation of the Magic Code? Surely others have enum properties that work with the [NinjascriptProperty] attribute?

                (By the way, this is an example of a property where the type conversion works in NT 7, but not in NT 8.)

                --EV
                Try taking off the TypeConverter attribute instead. I still think that that is where your problem lies.

                Comment


                  #9
                  Originally posted by -=Edge=- View Post
                  I initially struggle a bit with this myself.. I created this to test a public enum in an exported dll.. Just a simple modification to the SampleUniversalMovingAverage.. What I found strange was creating the enum outside both the indicator class and namespace.. (but it does seem to work)..


                  I see the problem, and I do not see a very good solution. The problem is that the enum definition needs to be seen by all of the Magic Code blocks, each of which is in its own namespace.

                  I can make my example work by doing as you did in your sample code -- put the enum definition in the global namespace. I do not like that answer because:
                  • It requires polluting the global namespace, with all of the well-known problems that entails. For one thing, if you ship such an indicator there is no guarantee that it will not collide with something your user is doing. You can rely on a naming convention, but that is something namespaces were invented to avoid. Bad code smell here, it seems to me.
                  • There is no guarantee that this solution is even possible. I can hold my nose and do that for an enum defined in my indicator, but what do I do if I want to use an enum defined somewhere else, some place that I have no control over?

                  This seems like a shortcoming of the Magic Code system, but I do not have any offhand suggestion to them for how to fix the problem. For now my indicator works, even if it does smell a little bad.

                  --EV

                  Comment


                    #10
                    Originally posted by koganam View Post
                    Try taking off the TypeConverter attribute instead. I still think that that is where your problem lies.
                    Thanks for the suggestion. I just tried that and it does not help. I really think the issue is the namespace one that -=Edge=- pointed out and that my previous posting talked about.

                    --EV
                    Last edited by ETFVoyageur; 08-03-2015, 03:32 PM.

                    Comment


                      #11
                      Originally posted by ETFVoyageur View Post
                      Thanks for the suggestion. I just tried that and it does not help. I really think the issue is the namespace one that -=Edge=- pointed out and that my previous posting talked about.

                      --EV
                      Here is a trivial, quick and dirty, example that I just whipped out. It compiles and runs. Sorry, I do not see the problem.

                      It is using a custom namespace: not polluting the Global Namespace.
                      Attached Files
                      Last edited by koganam; 08-03-2015, 03:47 PM.

                      Comment


                        #12
                        Originally posted by koganam View Post
                        Here is a trivial, quick and dirty, example that I just whipped out. It compiles and runs. Sorry, I do not see the problem.

                        It is using a custom namespace: not polluting the Global Namespace.
                        Thanks.

                        Duh ... I don't know why that did not instantly occur to me. All that is required is for the enum to be in some namespace that you are willing to provide a "using" statement for. It also handles the case of using someone else's enum, provided you are willing to use a "using" statement for whatever namespace that enum comes from.

                        --EV

                        Comment


                          #13
                          Originally posted by ETFVoyageur View Post
                          I guess the attribute use is self-evident once you think about it. It appears to me that [NinjaScriptProperty] means "this property can be used from NinjaScript". Is that right? It is unrelated to GUI use (e.g. Indicators dialog) but could be used to enable/disable access to that property from NinjaScript (not that I have a use case for disabling such access).

                          Adding [NinjaScriptProperty] to an enum property seems to be causing a problem with the Magic Code, though. When I added the attribute, I got a compiler error The error message refers to a Magic Code line
                          Code:
                                  public VsaModelIndicator VsaModelIndicator(DemoEnum demoEnumProperty, string stringProperty, int length, double height, bool enableDisableProperty, bool onOffProperty, bool yesNoProperty, xxxEnum xxxProperty)
                          Here is my code that triggers the error message. Removing [NinjaScriptProperty] avoids the error (because the Magic Code no longer tries to use it) but that is presumably undesirable.
                          Code:
                                  public enum DemoEnum {
                                      [EnumDisplayName("User-friendly label for Value 1")]        value1,
                                      [EnumDisplayName("User-friendly label for Value 2")]        value2
                                  }
                                  private DemoEnum demoEnumProperty = DemoEnum.value2;
                                  // Either of the following two forms of the [DefaultValue] attribute work -- choice is just personal style
                                      [DefaultValue(DemoEnum.value2)]
                                      //[DefaultValue(typeof(DemoEnum), "value2")]
                                  [TypeConverter(typeof(EnumDescriptionConverter))]
                                  [ReadOnly(false)]                                // Do allow the user to change the value
                                  [Browsable(true)]                               // Do show in the indicator property dialog
                                  [NinjaScriptProperty]                            // So the property can be used from NinjaScript, such as in a Strategy
                                  [Display(Order = 0, Name = "User-friendly enum property", GroupName = demoCategory,
                                          Description = "This property demonstrates an enum property using user-friendly labels")]
                                  public DemoEnum DemoEnumProperty
                                  {
                                      get { return demoEnumProperty; }
                                      set { demoEnumProperty = value; }
                                  }
                          Am I doing something wrong, or is this a bug in the generation of the Magic Code? Surely others have enum properties that work with the [NinjascriptProperty] attribute?

                          (By the way, this is an example of a property where the type conversion works in NT 7, but not in NT 8.)

                          --EV
                          Not quite. Any public property will be usable from NinjaScript. The [NinjaScriptProperty] attribute simply ensures that the property is part of the instance constructor, and must hence be specified, when the object is declared. cf: NT7, where a [GridCategory] property meant that it was a part of the instance constructor, but [Category] was not necessarily so (unless the Category was explicitly named "Parameters").
                          Last edited by koganam; 08-03-2015, 05:47 PM.

                          Comment


                            #14
                            Originally posted by koganam View Post
                            Not quite. Any public property will be usable from NinjaScript. The [NinjaScriptProperty] attribute simply ensures that the property is part of the instance constructor, and must hence be specified, when the object is declared. cf: NT7, where a [GridCategory] property meant that it was a part of the instance constructor, but [Category] was not necessarily so (unless the Category was explicitly named "Parameters".
                            Thanks for the explanation

                            --EV

                            Comment


                              #15
                              Originally posted by koganam View Post
                              Here is a trivial, quick and dirty, example that I just whipped out. It compiles and runs. Sorry, I do not see the problem.
                              The problem comes when you export that to a compiled assembly (protected dll or not) and try to import it into another system..


                              -=Edge=-
                              NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mmenigma, Yesterday, 03:25 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by kujista, Today, 05:44 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post kujista
                              by kujista
                               
                              Started by ZenCortexCLICK, Today, 04:58 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post ZenCortexCLICK  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              172 responses
                              2,281 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Irukandji, Yesterday, 02:53 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post Irukandji  
                              Working...
                              X