• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 RB104, Today, 06:06 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by jtrading82, 05-25-2018, 09:59 AM
            9 responses
            978 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by syxforex, Today, 12:11 AM
            2 responses
            15 views
            0 likes
            Last Post syxforex  
            Started by aslane, Today, 02:31 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by stoner, 10-16-2019, 01:38 PM
            5 responses
            51 views
            0 likes
            Last Post sledge
            by sledge
             
            Working...
            X