• 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

Average True Range Displayed in Ticks

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

    Average True Range Displayed in Ticks

    hello all,

    Thanks in advance for any help.

    NT has a great indicator in ATR (Average True Range). it displays its results as a fluctuation of the range. for example, for the Euro, it might display .000206 as the average true range, which is of course correct, but I would like to see that info in terms of ticks, which would be 2.06 ticks.

    is there an indicator (perhaps someone has already developed it) or, if not, how could I get it to show in this format? I'm not a great coder, but the logic would be easy, basically...

    ATR / instrument tick size = ATR in terms of ticks

    I don't know where to pull the instrument's tick size from (i know where it is manually, but NT should be able to pull it for each instrument individually since it is different for each instrument).

    Thanks for pointing me in the right direction.

    #2
    Hello outstretchedarm,

    Thank you for your post.

    Are you asking for 2.06 ticks? Or 2 points and 6 ticks? Or just to see the ATR move in the regards of the ticks of the instrument it is applied to?

    The tick size of the instrument is accessed in NinjaScript with TickSize: http://www.ninjatrader.com/support/h...7/ticksize.htm
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Edit the indicator and replace OnBarUpdate() with the following code:

      Code:
      protected override void OnBarUpdate()
      {
          if (CurrentBar == 0)
              Value.Set((High[0] - Low[0])/TickSize);
          else
          {
              double trueRange = High[0] - Low[0];
              trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
              Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange/TickSize) / Math.Min(CurrentBar + 1, Period));
          }
      }
      Then save the indicator under a new name and compile via F5.

      Originally posted by outstretchedarm View Post
      hello all,

      Thanks in advance for any help.

      NT has a great indicator in ATR (Average True Range). it displays its results as a fluctuation of the range. for example, for the Euro, it might display .000206 as the average true range, which is of course correct, but I would like to see that info in terms of ticks, which would be 2.06 ticks.

      is there an indicator (perhaps someone has already developed it) or, if not, how could I get it to show in this format? I'm not a great coder, but the logic would be easy, basically...

      ATR / instrument tick size = ATR in terms of ticks

      I don't know where to pull the instrument's tick size from (i know where it is manually, but NT should be able to pull it for each instrument individually since it is different for each instrument).

      Thanks for pointing me in the right direction.
      Last edited by Harry; 06-27-2013, 08:26 AM.

      Comment


        #4
        Originally posted by Harry View Post
        Edit the indicator and replace OnBarUpdate() with the following code:

        Code:
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 0)
                Value.Set((High[0] - Low[0])/TickSize);
            else
            {
                double trueRange = High[0] - Low[0];
                trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
                Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / (Math.Min(CurrentBar + 1, Period)*TickSize));
            }
        }
        Then save the indicator under a new name and compile via F5.

        wow if this works this will be awesome. thanks; I'm going to give it a try tomorrow.

        Comment


          #5
          Hi,

          I was attempting the same change but I am getting a blank ATR plot back. It displays values from 0-1 on the y-axis. Any ideas?

          Thanks,
          darmbk.

          Comment


            #6
            Hello darmbk,

            Thank you for your post.

            Can you post your code here so I may investigate this matter further?
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              The code below should be the original ATR code with the change suggested earlier in this thread...

              Thanks darmbk.

              //
              // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
              // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
              //

              #region Using declarations
              using System;
              using System.Diagnostics;
              using System.Drawing;
              using System.Drawing.Drawing2D;
              using System.ComponentModel;
              using System.Xml.Serialization;
              using NinjaTrader.Data;
              using NinjaTrader.Gui.Chart;
              #endregion

              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
              /// <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>
              [Description("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.")]
              public class qATR : Indicator
              {
              #region Variables
              private int period = 14;
              #endregion

              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
              Add(new Plot(Color.Green, "ATR"));
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              if (CurrentBar == 0)
              Value.Set((High[0] - Low[0])/TickSize);
              else
              {
              double trueRange = High[0] - Low[0];
              trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
              Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / (Math.Min(CurrentBar + 1, Period)*TickSize));
              }
              }

              #region Properties
              /// <summary>
              /// </summary>
              [Description("Numbers of bars used for calculations")]
              [GridCategory("Parameters")]
              public int Period
              {
              get { return period; }
              set { period = Math.Max(1, value); }
              }
              #endregion
              }
              }

              Comment


                #8
                Sorry, when I had suggested the code, I did not have the time to test it. Please replace OnBarUpdate() with

                Code:
                protected override void OnBarUpdate()
                {
                	if (CurrentBar == 0)
                		Value.Set((High[0] - Low[0])/TickSize);
                	else
                	{
                		double trueRange = High[0] - Low[0];
                		trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
                		Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange/TickSize) / Math.Min(CurrentBar + 1, Period));
                	}
                }
                You just need to change one line. I had inserted TickSize in the wrong place.

                I have also changed the code in my post below, just in case somebody else copies it.

                Comment


                  #9
                  No apologies necessary. Independently, I was making the exact same mistake! The revised code works perfectly.

                  Many thanks,
                  darmbk.

                  Comment


                    #10
                    ATRtick8 should be the correct version for the code above for NinjatTrader 8. The initial period in the ATR theory is 14 but this is set to 10 and you may change it on your own.
                    Attached Files

                    Comment


                      #11
                      Originally posted by JMont1 View Post
                      ATRtick8 should be the correct version for the code above for NinjatTrader 8. The initial period in the ATR theory is 14 but this is set to 10 and you may change it on your own.
                      any way to round it up to the nearest tick?

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by SamuelO, 05-22-2020, 11:58 AM
                      7 responses
                      60 views
                      0 likes
                      Last Post guidoisot  
                      Started by Cimxrice, Today, 01:25 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post Cimxrice  
                      Started by Z-Starter, Today, 01:21 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post Z-Starter  
                      Started by atman, Today, 12:37 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post atman
                      by atman
                       
                      Started by random9570, Yesterday, 09:01 PM
                      1 response
                      13 views
                      0 likes
                      Last Post Fulcanelli  
                      Working...
                      X