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

How to show value on screen

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

    How to show value on screen

    How can I get the ATR value to show onscreen, perhaps the top right below another text printed at the top right?

    I'd like to multiple the ATR by 33% of the daily ATR and print on current chart


    {
    #region Variables
    // Wizard generated variables

    private int period = 20; //Default ATR Period
    private int trueRange;
    // 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()
    {
    DrawOnPricePanel = true;
    Overlay = true;
    Add(PeriodType.Minute, 1440);

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1)
    return;

    if (CurrentBar == 0)
    Value.Set(High[0] - Low[0]);
    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));

    }

    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove


    [Description("")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }
    #endregion
    }
    Last edited by brucelevy; 09-29-2015, 07:21 AM.

    #2
    Hello brucelevy,
    Thank you for your post.


    You could use DrawTextFixed(), as this will draw text in one of 5 available pre-defined fixed locations on panel 1 (price panel) of a chart.


    Here is an example of what to add in the else statement of your indicator:

    Code:
    [COLOR=#000000][FONT=Tahoma] [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](CurrentBars[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] <= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] || CurrentBars[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] <= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT][/LEFT]
    [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ;[/SIZE][/FONT][/LEFT]
    [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]else[/COLOR][/SIZE][/FONT][/LEFT]
    [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]{[/SIZE][/FONT][/LEFT]
    [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]Value[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] = ((ATR(BarsArray[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]], period)[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]) * (ATR(BarsArray[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ], period)[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]] / [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]));[/SIZE][/FONT][/LEFT]
    [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]DrawTextFixed([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"ATR Value"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] , [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"The Current ATR Value x 1/3rd of Daily ATR is "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] + Value, TextPosition.TopRight);[/SIZE][/FONT][/LEFT]
    [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]}[/SIZE][/FONT][/LEFT]
    [/FONT][/COLOR]  [/FONT][/COLOR]




    DrawTextFixed() Help Guide
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Not getting anything to show up on the screen, any idea what it could be?

      #region Variables
      // Wizard generated variables
      private int areaOpacity = 5;
      private int period = 20; //Default ATR Period
      private int trueRange;
      // 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()
      {
      DrawOnPricePanel = true;
      Overlay = true;
      AutoScale = false;
      Add(PeriodType.Day, 1);

      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      if (CurrentBar == 0)
      Value.Set(High[0] - Low[0]);
      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));

      }
      if(CurrentBars[0] <= 0 || CurrentBars[1] <= 0)
      return ;
      else
      {
      Value[0] = ((ATR(BarsArray[0], period)[0]) * (ATR(BarsArray[1], period)[0] / 3));
      DrawTextFixed("ATR Value", "The Current ATR Value x 1/3rd of Daily ATR is " + Value, TextPosition.Center, Color.Black, ChartControl.Font, Color.Gray, Color.Blue, areaOpacity);

      }

      }

      Comment


        #4
        Hello brucelevy,
        I have included an example to show you exactly how the code should look under OnBarUpdate()

        Code:
            protected override void OnBarUpdate()
                {
                    if(CurrentBars[0] <= 0 || CurrentBars[1] <= 0)
                        return ;
                    else
                    {
                        Value[0] = ((ATR(BarsArray[0], period)[0]) * (ATR(BarsArray[1], period)[0] / 3));
                        DrawTextFixed("ATR Value", "The Current ATR Value x 1/3rd of Daily ATR is " + Value, TextPosition.TopRight, Color.Black, ChartControl.Font, Color.Gray, Color.Blue, 3);
                    }   
                }
        Shawn B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Shawn, works great! I am getting an overlap since I already have a drawtext on the top left, can it be adjusted at all?

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by mgco4you, Today, 09:46 PM
          0 responses
          1 view
          0 likes
          Last Post mgco4you  
          Started by Rapine Heihei, Today, 08:19 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Rapine Heihei, Today, 08:25 PM
          0 responses
          6 views
          0 likes
          Last Post Rapine Heihei  
          Started by f.saeidi, Today, 08:01 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Rapine Heihei, Today, 07:51 PM
          0 responses
          8 views
          0 likes
          Last Post Rapine Heihei  
          Working...
          X