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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        87 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        106 views
        0 likes
        Last Post CarlTrading  
        Working...
        X