Announcement

Collapse
No announcement yet.

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:

    http://www.ninjatrader.com/support/f...ead.php?t=4991
    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 glivv, Today, 09:17 AM
            0 responses
            5 views
            0 likes
            Last Post glivv
            by glivv
             
            Started by cmv727, Today, 08:48 AM
            0 responses
            6 views
            0 likes
            Last Post cmv727
            by cmv727
             
            Started by Kaiviti57, Today, 04:13 AM
            2 responses
            8 views
            0 likes
            Last Post bltdavid  
            Started by aslane, Today, 08:02 AM
            0 responses
            7 views
            0 likes
            Last Post aslane
            by aslane
             
            Started by DTSSTS, Today, 07:03 AM
            0 responses
            15 views
            0 likes
            Last Post DTSSTS
            by DTSSTS
             
            Working...
            X