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

Help Removing Smoothing from ATR

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

    Help Removing Smoothing from ATR

    Hello,

    I'm a complete novice coder and I'm trying to modify the built in ATR indicator in Ninjatrader 8 to remove the weighted average of the period and get a simple average instead.

    I think line 61 is where I need to make a change but I've had no luck trying to figure it out on my own.

    Here's line 61:
    Value[0] = ((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);

    Can anyone confirm whether this is where I should be making modifications and, if so, what the correct syntax is if I don't want a weighted average?

    Thanks in advance for any asistance.

    #2
    Hello MRToby,

    Thank you for your note.

    Could you please clarify what you are referring to when you say you’d like to change the ATR formula from a weighted to a simple average? Could you share a formula of the calculation you’d like to use?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Yes. Thank you.

      The built in indicator uses Wilder's original smoothing which goes:

      ((period -1) * Value[1] + true range) / period

      I'm looking to get rid of the multiplication that creates an exponential moving average of the Rue Ranges. I want to produce a simple moving average of the values instead. In theory that would simply add up the True Range values for the last n bars and divide them by n (where n = period)

      As I understand it, if the period were 5, would be:
      (Value [4] + Value [3] + Value [2] + Value [1] + true range) / 5

      However, when I change the code to what I wrote above, I get nothing. Clearly I've missed something important. I just don't know what it is.
      Last edited by MRToby; 12-21-2016, 03:55 PM.

      Comment


        #4
        Hello MRToby,

        To accomplish this what you could do is create an new data series variable then assign the value to trueRange. Next set the plot equal to the SMA of that data series.

        Under #region Variables,
        private DataSeries trueRangeSeries;

        Under Initialize,
        trueRangeSeries=new DataSeries(this);

        Then under OnBarUpdate after trueRange is given its value, add the following,

        trueRangeSeries[0]=trueRange;
        Value.Set(SMA(trueRangeSeries,Period)[0]);

        This will give you the average of x Periods truerange.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Almost there.

          Originally posted by NinjaTrader_AlanP View Post
          Hello MRToby,

          Under #region Variables,
          private DataSeries trueRangeSeries;

          Under Initialize,
          trueRangeSeries=new DataSeries(this);

          Then under OnBarUpdate after trueRange is given its value, add the following,

          trueRangeSeries[0]=trueRange;
          Value.Set(SMA(trueRangeSeries,Period)[0]);
          I think I'm almost there. I'm just having trouble getting the code in the right place and it wont compile. I've attached my code so you can see what I've done.

          On line 37, I pasted:
          private DataSeries trueRangeSeries;
          but that seems to be in the wrong place.

          On Line 42, I pasted:
          trueRangeSeries=new DataSeries(this);
          This isn't giving me an error, but I'm still not sure I've got it in the right place.

          I think I got the last piece of code in the right place, I'm just struggling with the first two.

          Thanks for your patient assistance..
          Attached Files

          Comment


            #6
            Hello MRToby,

            The code I previously provided was for NT7, my apologies.

            I have provided a copy of ATR modified how you desire.
            Attached Files
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              That makes me feel slightly less ignorant about my confusion, and I'm starting to grasp some o fthe coding concepts. Thanks for your help. This is exactly what I was trying to do.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by MarianApalaghiei, Today, 10:49 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by love2code2trade, Yesterday, 01:45 PM
              4 responses
              28 views
              0 likes
              Last Post love2code2trade  
              Started by funk10101, Today, 09:43 PM
              0 responses
              8 views
              0 likes
              Last Post funk10101  
              Started by pkefal, 04-11-2024, 07:39 AM
              11 responses
              37 views
              0 likes
              Last Post jeronymite  
              Started by bill2023, Yesterday, 08:51 AM
              8 responses
              46 views
              0 likes
              Last Post bill2023  
              Working...
              X