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

Custom ATR Indicator

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

    Custom ATR Indicator

    Hi! First off, im not a coder, i got this indicator from futures.io, someone had posted it but its exactly what i needed. It is a clean ATR indicator that just places a number at the bottom right had corner of the screen instead of the default NT7 indicator which has a pointless line graph that you can't get rid of, only minimize. Anyway, the indicator works great but I just need to be able to make the font bigger because its tiny and hard to see. Also it would be nice to be able to change the font and color (but its not a necessity for me) I just need the indicator font bigger. if anyone can help with this and what the coding is and exactly where it needs to go, i'd really appreciate it. thanks. il copy and paste it and il also include it as an attachment


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

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class ATRText : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int period = 14; // Default setting for Period
    // User defined variables (add any user defined variables below)
    #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()
    {
    Overlay = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    if(CurrentBar>Period)
    {
    string text = string.Format("ATR({0}): {1}",Period,Math.Round(ATR(Period)[0],5));
    DrawTextFixed("Nebraska", text , TextPosition.BottomRight);
    }
    }

    #region Properties

    [Description("Length of ATR")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    public partial class Indicator : IndicatorBase
    {
    private ATRText[] cacheATRText = null;

    private static ATRText checkATRText = new ATRText();

    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    public ATRText ATRText(int period)
    {
    return ATRText(Input, period);
    }

    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    public ATRText ATRText(Data.IDataSeries input, int period)
    {
    if (cacheATRText != null)
    for (int idx = 0; idx < cacheATRText.Length; idx++)
    if (cacheATRText[idx].Period == period && cacheATRText[idx].EqualsInput(input))
    return cacheATRText[idx];

    lock (checkATRText)
    {
    checkATRText.Period = period;
    period = checkATRText.Period;

    if (cacheATRText != null)
    for (int idx = 0; idx < cacheATRText.Length; idx++)
    if (cacheATRText[idx].Period == period && cacheATRText[idx].EqualsInput(input))
    return cacheATRText[idx];

    ATRText indicator = new ATRText();
    indicator.BarsRequired = BarsRequired;
    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
    indicator.Input = input;
    indicator.Period = period;
    Indicators.Add(indicator);
    indicator.SetUp();

    ATRText[] tmp = new ATRText[cacheATRText == null ? 1 : cacheATRText.Length + 1];
    if (cacheATRText != null)
    cacheATRText.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheATRText = tmp;
    return indicator;
    }
    }
    }
    }

    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
    public partial class Column : ColumnBase
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.ATRText ATRText(int period)
    {
    return _indicator.ATRText(Input, period);
    }

    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    public Indicator.ATRText ATRText(Data.IDataSeries input, int period)
    {
    return _indicator.ATRText(input, period);
    }
    }
    }

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.ATRText ATRText(int period)
    {
    return _indicator.ATRText(Input, period);
    }

    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    public Indicator.ATRText ATRText(Data.IDataSeries input, int period)
    {
    if (InInitialize && input == null)
    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

    return _indicator.ATRText(input, period);
    }
    }
    }
    #endregion


    Attached Files

    #2
    Hello RockRiver, thanks for your post.

    You will need to change "DrawTextFixed" on line 46 of the script. You can change it to this and the text will be large, to edit the size, just change the "24" within the Font constructor.

    Code:
    DrawTextFixed("Nebraska", text, TextPosition.BottomRight, Color.Black, new Font("Arial", 24, FontStyle.Regular),Color.White, Color.Black, 1);
    Best regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Awesome! Thank you for the code, everything works as it should! I appreciate your help!

      Comment


        #4
        Originally posted by NinjaTrader_ChrisL View Post
        Hello RockRiver, thanks for your post.

        You will need to change "DrawTextFixed" on line 46 of the script. You can change it to this and the text will be large, to edit the size, just change the "24" within the Font constructor.

        Code:
        DrawTextFixed("Nebraska", text, TextPosition.BottomRight, Color.Black, new Font("Arial", 24, FontStyle.Regular),Color.White, Color.Black, 1);
        Best regards.
        Also can you tell me the code for making the indicator only read 2 decimal places instead of 5? thanks
        Attached Files

        Comment


          #5
          Hello RockRiver, thanks for your reply.

          That is the Math.Round() method on line 45 of the script.

          Change:
          string text = string.Format("ATR({0}): {1}",Period,Math.Round(ATR(Period)[0],5));

          to this for 2 decimal places:

          string text = string.Format("ATR({0}): {1}",Period,Math.Round(ATR(Period)[0],2));

          Best regards.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Great! Thanks, that was really easy! You are awesome sir! I wish you a good week! Thanks again for your help, couldnt have done it without you. Now the indicator is exactly as I need it to be!

            Comment


              #7
              I tried to replicate this code for NT8 but with little success. Do you have an updated file you can share?

              Comment


                #8
                Hello cpritch36, thanks for posting.

                Unfortunately, I do not have the NinjaTrader 8 version of the ATRText script that RockRiver was working on. Maybe they could post it.

                Best regards.
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bortz, 11-06-2023, 08:04 AM
                47 responses
                1,607 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                9 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                19 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                6 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                15 views
                0 likes
                Last Post Javierw.ok  
                Working...
                X