Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tip: How to exclude visual settings from the parameter list of an indicator?

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

    Tip: How to exclude visual settings from the parameter list of an indicator?

    When you develop a custom indicator, some of the properties determine its behavior, for example, the period for a moving average. Some of them determine how it plots, for example, the color of an arrow. Many of us add an attribute, [Categogy("Parameters")], to the properties so that they will display together in the "Parameters" section in the Indicator dialog box, separate from the "General" section. Pretty neat! We pat ourselves on the shoulders.

    However, the auto-generated construstor for your indicator now have all the properties as parameters. To use your indicator in a strategy or another indicator, you are forced to set all the parameters even though you do not care about the visual aspect of the indicator under the occassion. For example, you want to type MyMA(period) instead of MyMA(period, Color.Red). If your indicator has quite a few visual settings, it becomes annoying quickly.

    What can we do? We have no control over how the constructors are generated, right? Well, not directly. My experiment shows that Parameters is a special category name. The NinjaScript compiler inspects your code and adds every property with that attribute to the list of parameters for the constructor.

    Actually, you can come up with any category name to use. For example, if you add [Categogy("Visual")] to all the properties related to plotting, they will all display in a "Visual" section in the Indicator dialog box. And...they all disapper from the contructor's parameter list! You can type MyMA(period) to your heart's content. Now that's neat!
    Last edited by KamaCoder Eric; 05-21-2008, 04:53 PM.

    #2
    Originally posted by KamaCoder Eric View Post
    When you develop a custom indicator, some of the properties determine its behavior, for example, the period for a moving average. Some of them determine how it plots, for example, the color of an arrow. Many of us add an attribute, [Categogy("Parameters")], to the properties so that they will display together in the "Parameters" section in the Indicator dialog box, separate from the "General" section. Pretty neat! We pat ourselves on the shoulders.

    However, the auto-generated construstor for your indicator now have all the properties as parameters. To use your indicator in a strategy or another indicator, you are forced to set all the parameters even though you do not care about the visual aspect of the indicator under the occassion. For example, you want to type MyMA(period) instead of MyMA(period, Color.Red). If your indicator has quite a few visual settings, it becomes annoying quickly.

    What can we do? We have no control over how the constructors are generated, right? Well, not directly. My experiment shows that Parameters is a special category name. The NinjaScript compiler inspects your code and adds every property with that attribute to the list of parameters for the constructor.

    Actually, you can come up with any category name to use. For example, if you add [Categogy("Visual")] to all the properties related to plotting, they will all display in a "Visual" section in the Indicator dialog box. And...they all disapper from the contructor's parameter list! You can type MyMA(period) to your heart's content. Now that's neat!
    Hi, Is there a way to do that in the strategies?.

    Regards

    Comment


      #3
      Yes you can. Done the same way.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by Josh View Post
        Yes you can. Done the same way.
        I try to do it on strategies but I can not, What I'm doing wrong? Attach is the complete code in case you need to take a look.


        #region Properties
        /// <summary>
        /// </summary>
        [Description("Period for fast MA")]
        [Category("My Parameters")]
        public int Fast
        {
        get { return fast; }
        set { fast = Math.Max(1, value); }
        }

        /// <summary>
        /// </summary>
        [Description("Period for slow MA")]
        [Category("My Own Parameters")]
        public int Slow
        {
        get { return slow; }
        set { slow = Math.Max(1, value); }
        }
        #endregion
        Attached Files

        Comment


          #5
          Guys, setting anything else than "Parameter" in the category attribute on properties is not supported. It may or may not work as expected for indicators or strategies. You'd need to find out by yourself. In any case this is beyond what we can provide support for.

          Thanks for your understanding.
          DierkNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by wehewwehd, Today, 11:10 AM
          0 responses
          1 view
          0 likes
          Last Post wehewwehd  
          Started by my-trade, Today, 10:45 AM
          0 responses
          7 views
          0 likes
          Last Post my-trade  
          Started by localappleseed, Today, 09:51 AM
          0 responses
          4 views
          0 likes
          Last Post localappleseed  
          Started by wehewwehd, Today, 09:13 AM
          0 responses
          4 views
          0 likes
          Last Post wehewwehd  
          Started by aaajv, Yesterday, 06:45 AM
          3 responses
          22 views
          0 likes
          Last Post NinjaTrader_ThomasC  
          Working...
          X