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 helpwanted, Today, 03:06 AM
            1 response
            11 views
            0 likes
            Last Post sarafuenonly123  
            Started by Brevo, Today, 01:45 AM
            0 responses
            9 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            5 views
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            242 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            387 views
            1 like
            Last Post Gavini
            by Gavini
             
            Working...
            X