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 adeelshahzad, Today, 03:54 AM
        5 responses
        32 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        7 responses
        32 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        21 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Working...
        X