• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

get and set in Properties

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

    get and set in Properties

    Hello,
    I have a question I should have asked a long time ago. Can someone please explain this section of code to me. It's pretty common among indicators. Thanks.
    [Description("Number of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }

    #2
    Hello CaptainAmericaXX,

    Thanks for your post.

    [Description("Number of bars used for calculations")] - This will provide "help" text that appears in the box below the indicator parameters. When you click on the specific parameter, this help text,"Number of bars used for calculations" would appear.

    [GridCategory("Parameters")] - Identifies what section the property will appear in.

    public int Period - This is a variable declaration where public means that it can be seen outside of the ninjascript (such as the user interface panel or if other ninjascript calls this ninjascript). int declares the variable named Period an Integer type.

    get { return period; } - This gets (retrieves) the value stored in the private int variable named "period". The private variable named "period" must be declared in your regions variable. This is the variable your code would work with

    set { period = Math.Max(1, value); } - This will set the value of Period and period according to the greater of 1 or the value of Period.

    Together the get/set make the Period property a read/write type.

    Here is a link to a more formal generic answer on the get/set accessors: https://msdn.microsoft.com/en-us/library/w86s7x04.aspx
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul,
      So what is the "value" in the statement:
      set { period = Math.Max(1, value); }
      value is never declared anywhere in the code.
      Last edited by CaptainAmericaXX; 02-02-2017, 09:06 PM.

      Comment


        #4
        Hello CaptainAmericaXX,

        Thanks for your reply.

        Sorry I missed that.

        Here is a link for clarity on the use of value: https://msdn.microsoft.com/en-us/library/a1khb4f8.aspx
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Conall, Today, 06:11 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by CaptainAmericaXX, Today, 07:41 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by Longhornmark, Today, 07:06 AM
        2 responses
        7 views
        0 likes
        Last Post Longhornmark  
        Started by 2sureshk, Today, 07:29 AM
        0 responses
        5 views
        0 likes
        Last Post 2sureshk  
        Started by uday12, Yesterday, 10:26 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Working...
        X