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

Text Under Bar

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

    Text Under Bar

    I am creating an indicator that will show a blue Up Arrow under the bar, have text saying "Buy Signal" under it and provide sound. I can get the blue Up Arrow to show on the chart but can't get the text to show underneath. Below is my code. What am I doing wrong?

    if(High[2]>High[1] && Low[2]<Low[1])
    {
    Draw.ArrowUp(this, "Buy Signal" + CurrentBar, true, 0, Low[0] - 3 * TickSize, Brushes.Blue);
    PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav");​
    }

    #2
    Hello algospoke,

    Thanks for your post.

    The Draw.ArrowUp() method only draws an up arrow on the chart. It does not draw text on the chart.

    Where you are passing in "Buy Signal" is the Tag parameter of the Draw.ArrowUp() drawing object being drawn on the chart. This is not text that appears on the chart.

    You would need to call the Draw.Text() method in your script one line after the Draw.ArrowUp() method to draw text on the chart when an arrow is being drawn on the chart.

    Please see the help guide documentation below for more information about Draw.Text().

    DrawText(): https://ninjatrader.com/support/help.../draw_text.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Brandon,

      I added the Draw.Text() but I still don't see any text on the chart. I only see the up arrows. See attached pic. Below is my code. What am I doing wrong?

      HTML Code:
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion
      
      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public class Demo2 : Indicator
          {
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Indicator here.";
                      Name                                        = "Demo2";
                      Calculate                                    = Calculate.OnBarClose;
                      IsOverlay                                    = true;
                      DisplayInDataBox                            = true;
                      DrawOnPricePanel                            = true;
                      DrawHorizontalGridLines                        = true;
                      DrawVerticalGridLines                        = true;
                      PaintPriceMarkers                            = true;
                      ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                      //See Help Guide for additional information.
                      IsSuspendedWhileInactive                    = true;
                  }
                  else if (State == State.Configure)
                  {
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  if (CurrentBar <= 5)
                      return;
                  if(High[2]>High[1] && Low[2]<Low[1])
                  {
                      Draw.ArrowUp(this, "Buy Signal" + CurrentBar, true, 0, Low[0] - 3 * TickSize, Brushes.Blue);
                      PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav");
                      Draw.Text(this,"tag1","Text to draw",10,1000,Brushes.Blue);
                  }
              }
          }
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
              private Demo2[] cacheDemo2;
              public Demo2 Demo2()
              {
                  return Demo2(Input);
              }
      
              public Demo2 Demo2(ISeries<double> input)
              {
                  if (cacheDemo2 != null)
                      for (int idx = 0; idx < cacheDemo2.Length; idx++)
                          if (cacheDemo2[idx] != null &&  cacheDemo2[idx].EqualsInput(input))
                              return cacheDemo2[idx];
                  return CacheIndicator<Demo2>(new Demo2(), input, ref cacheDemo2);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
          public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          {
              public Indicators.Demo2 Demo2()
              {
                  return indicator.Demo2(Input);
              }
      
              public Indicators.Demo2 Demo2(ISeries<double> input )
              {
                  return indicator.Demo2(input);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          {
              public Indicators.Demo2 Demo2()
              {
                  return indicator.Demo2(Input);
              }
      
              public Indicators.Demo2 Demo2(ISeries<double> input )
              {
                  return indicator.Demo2(input);
              }
          }
      }
      
      #endregion
      
      ​
      Attached Files

      Comment


        #4
        Hello algospoke,

        Currently, the text is being drawn 10 bars back from the current bar on the chart at the price of 1000.

        You would need to modify the Draw.Text() method to have a unique tag name (similar to your Draw.ArrowUp() method), the barsAgo argument should be set to 0, and you would need to make sure you are using a price below the bar (such as Low[0] - 6 * TickSize).

        See this help guide page for more information about Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm
        Last edited by NinjaTrader_BrandonH; 03-05-2024, 08:32 AM.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Brandon - Awesome that worked! Appreciate the help

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by iceman2018, Today, 05:07 PM
          0 responses
          0 views
          0 likes
          Last Post iceman2018  
          Started by rhyminkevin, Today, 04:58 PM
          0 responses
          18 views
          0 likes
          Last Post rhyminkevin  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          6 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          49 views
          0 likes
          Last Post futtrader  
          Working...
          X