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 fwendolynlpxz, Today, 05:19 AM
            0 responses
            1 view
            0 likes
            Last Post fwendolynlpxz  
            Started by traderqz, Yesterday, 12:06 AM
            11 responses
            27 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by PaulMohn, Today, 03:49 AM
            0 responses
            8 views
            0 likes
            Last Post PaulMohn  
            Started by inanazsocial, Today, 01:15 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by rocketman7, Today, 02:12 AM
            0 responses
            11 views
            0 likes
            Last Post rocketman7  
            Working...
            X