Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about source code for ATR

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

    Question about source code for ATR

    I've been looking through the source code for the various indicators included with NT to learn the NT API, best practices, and to learn more about C# (I have a background in C and Java). There seems to be a pattern in the constructor for many of the indicators where a member variable is set to a parameter followed immediately by setting the parameter to the same member variable. I'm trying to understand why the second statement is necessary.

    Here's an excerpt of the ATR source for reference (...\My Documents\NinjaTrader 6.5\bin\Custom\Indicator\@ATR.cs):
    Code:
            private ATR[] cacheATR = null;
            private static ATR checkATR = new ATR();
    
            /// <summary>
            /// The Average True Range (ATR) is a measure of volatility. It was introduced by Welles Wilder in his book 'New Concepts in Technical Trading Systems' and has since been used as a component of many indicators and trading systems.
            /// </summary>
            /// <returns></returns>
            public ATR ATR(Data.IDataSeries input, int period)
            {
                checkATR.Period = period;
                period = checkATR.Period;
    Why is the last line necessary?

    Thanks,
    Erik P

    #2
    Hi Erik,

    You should never change anything in that region of the code. That region is automatically generated and is unfortunately outside the scope of what we can offer support for.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I had the same thought. Its because "checkATR.Period" *may* have some code in its initializer that verifies the input. For example, "1" being the minimum size for an int input.

      Comment


        #4
        Originally posted by Gumphrie View Post
        I had the same thought. Its because "checkATR.Period" *may* have some code in its initializer that verifies the input. For example, "1" being the minimum size for an int input.
        Gumphrie,

        Thanks. That makes sense.

        Cheers,
        Erik

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X