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

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

    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?

            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 GLFX005, Today, 03:23 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post GLFX005
                      by GLFX005
                       
                      Started by XXtrader, Yesterday, 11:30 PM
                      2 responses
                      11 views
                      0 likes
                      Last Post XXtrader  
                      Started by Waxavi, Today, 02:10 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post Waxavi
                      by Waxavi
                       
                      Started by TradeForge, Today, 02:09 AM
                      0 responses
                      11 views
                      0 likes
                      Last Post TradeForge  
                      Started by Waxavi, Today, 02:00 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post Waxavi
                      by Waxavi
                       
                      Working...
                      X