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

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 trilliantrader, Today, 03:01 PM
        2 responses
        17 views
        0 likes
        Last Post helpwanted  
        Started by ScottWalsh, Today, 06:52 PM
        2 responses
        16 views
        0 likes
        Last Post ScottWalsh  
        Started by cre8able, Today, 07:24 PM
        0 responses
        1 view
        0 likes
        Last Post cre8able  
        Started by Haiasi, Today, 06:53 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by ScottW, Today, 06:09 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X