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

public variables in UserDefinedMethods

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

    public variables in UserDefinedMethods

    Hi there

    I have all my methods in UserDefinedMethods.

    Most of the variables I have created are private and used in UserDefinedMethods.

    However, I had to make some variables public in order to use them to compare in an indicator I created.

    I find that odd because I am not changing their state just referencing their value. If I don't it won't compile due to the protection level.

    It is common practice for me to have variables as private so I don't have to worry about mistakenly changing their state in any indicators... is there any way to have it as private but still compare in an indicator like the below?

    SumOfBars >= LargestValue

    SumofBars is defined in public in UserDefinedMethods
    LargestValue is defined in public in UserDefinedMethods


    #2
    Hello,

    The best way to accomplish this is to declare the variables in UserDefinedMethod as private, but use a Public variable that "Get" the private variable internally.

    Please take a look at the region Properites section of the SampleBoolSeries from the following link:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks.

      I use the Get in the indicator?

      Comment


        #4
        Hello,

        You would use this from the UserDefinedMethod

        Code:
        public double ExposedVariable
                {
           // We need to call the Update() method to ensure our exposed variable is in up-to-date.
                    get { return exposedVariable; }
                }
        This will ensure that within the UserDefinedMethod the variable is private, but there will also be a public variable that gets set to these values.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Thanks, I initially made a typo but it works now in UserDefinedMethods...

          Comment


            #6
            Great, glad to hear it works.
            MatthewNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Belfortbucks, Today, 09:29 PM
            0 responses
            6 views
            0 likes
            Last Post Belfortbucks  
            Started by zstheorist, Today, 07:52 PM
            0 responses
            7 views
            0 likes
            Last Post zstheorist  
            Started by pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            151 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            6 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            33 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Working...
            X