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 draw text just below arrows

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

    How to draw text just below arrows

    Hi,

    I am trying to Draw a text below an Arrow (up/down)

    For Drawing arrows I use the DrawArrowUp/DrawArrowDown functions.

    and for text i use Draw Text functions.

    What I want is the text to be just below the Arrows. Following is the example code I have:

    DrawArrowUp(signalArrowTag, true , Time[0], Low[0] - TickSize,Color.Yellow);
    DrawText(signalTextTag,"HM",0,Low[0]- (5*TickSize),Color.Black);

    Normally it looks ok on the chart. but sometimes if the chart Yaxis scale was expanded, I get overlap of the text and the arrow shapes.

    Is there a way to code such that I get the text at fixed distance below/above the arrow?
    Meaning if there is a function I can query the length of the arrow, I can use the length as the offset for the Y attribute for DrawText function.

    Thanks in advance

    #2
    ystan79, there would unfortunately not be a function to measure and take into consideration the size of the rendering arrow here. There would be more options for custom drawing in the overriden Plot() method though, that is something you could look into for example for a custom marker.

    This is not something we could support fully yet officially, however NT is shipping with a small example as help to get going (CustomPlotSample).
    BertrandNinjaTrader Customer Service

    Comment


      #3
      DrawText() allows you the dynamical setting of a pixel offset. You can therefore display your text at a fixed distance from the high or low of the bar. And even better you can select a multiple of the font size as pixel offset.

      If I code an indicator, I pay attention that the distance between arrow and text dynamically adjusts to the arrow size and text font size.This feature is not available with DrawArrowUp() and DrawArrowDown(). Therefore I use DrawText() to plot triangles. For that purpose I select the the font Webdings and use the characters "5" and "6" which will show as triangles. This has the following advantages:

      - unlike the arrows the size of the triangles can be adjusted by changing the fontsize for the webdings characters
      - the pixel offset that comes with DrawText() can be set to a multiple of the fontsize and it will autoadjust if the user changes the size of the triangles

      Comment


        #4
        Thanks, Harry. This is seriously interesting stuff. Very useful to know.

        Cheers,

        Ed

        Comment


          #5
          Originally posted by ystan79 View Post
          Hi,

          I am trying to Draw a text below an Arrow (up/down)

          For Drawing arrows I use the DrawArrowUp/DrawArrowDown functions.

          and for text i use Draw Text functions.

          What I want is the text to be just below the Arrows. Following is the example code I have:

          DrawArrowUp(signalArrowTag, true , Time[0], Low[0] - TickSize,Color.Yellow);
          DrawText(signalTextTag,"HM",0,Low[0]- (5*TickSize),Color.Black);

          Normally it looks ok on the chart. but sometimes if the chart Yaxis scale was expanded, I get overlap of the text and the arrow shapes.

          Is there a way to code such that I get the text at fixed distance below/above the arrow?
          Meaning if there is a function I can query the length of the arrow, I can use the length as the offset for the Y attribute for DrawText function.

          Thanks in advance
          Use DrawText() to draw text arrows. That will give you precise control over all placements, as they are all really just text. Use the DrawText() override that allows you to specify the offset.

          Comment


            #6
            Yes, using Drawtext works for me!

            Many thanks for this helpful information

            Cheers!

            Comment


              #7
              Hello,

              I know this is the old thread but I struggle with Draw.Text() (Ninjatrader 8) method where my goal is to put triangle and text under the bar where triangle is created by Draw.Text() . Triangle is under the bar and text is under the triangle in line. Could you give me an example of code which can meet my idea.

              Thanks in advanced.

              Comment


                #8
                Originally posted by kanarkia View Post
                Hello,

                I know this is the old thread but I struggle with Draw.Text() (Ninjatrader 8) method where my goal is to put triangle and text under the bar where triangle is created by Draw.Text() . Triangle is under the bar and text is under the triangle in line. Could you give me an example of code which can meet my idea.

                Thanks in advanced.
                It is just text. Use a CR/LF to create a new line in the text, after the arrow.

                Comment


                  #9
                  Hi,

                  Thanks for the answer. The problem is to keep drawing object on precise place under or above the bar. I gave up. I started working with OnRender. Once again, thank you for the help.

                  Comment


                    #10
                    You can easily do this by using the pixel offset provided by Draw.Text. The pixel offset should depend on the font size.

                    The chart attached below uses Draw.Text to print the signals. Draw.Text is used twice, but with different pixel offsets.
                    Attached Files

                    Comment


                      #11
                      On your screen it looks great.Take a look on my example. Below the code which was used to draw.

                      NinjaTrader.Gui.Tools.SimpleFont newFont = new NinjaTrader.Gui.Tools.SimpleFont("Webdings",20);

                      Draw.Text(this,"UP" + bar,true, "5", CurrentBar-bar,Low[CurrentBar-bar],20,null, newFont, TextAlignment.Left, null, null, 10);

                      Triangle which is shown on screen should be drawn a little bit on the left. I tried many times to modify it and I can not handle this. Could you present your part of code which you allow to draw such beautiful objects?
                      Attached Files

                      Comment


                        #12
                        Originally posted by kanarkia View Post
                        On your screen it looks great.Take a look on my example. Below the code which was used to draw.

                        NinjaTrader.Gui.Tools.SimpleFont newFont = new NinjaTrader.Gui.Tools.SimpleFont("Webdings",20);

                        Draw.Text(this,"UP" + bar,true, "5", CurrentBar-bar,Low[CurrentBar-bar],20,null, newFont, TextAlignment.Left, null, null, 10);

                        Triangle which is shown on screen should be drawn a little bit on the left. I tried many times to modify it and I can not handle this. Could you present your part of code which you allow to draw such beautiful objects?

                        As you ask about NinjaTrader 8, we are definitely in the wrong thread here. But try to use TextAlignment.Center.

                        Comment


                          #13
                          You are right. Wrong place. Sorry. I tried many things and I believe that something in my code has influnce on it. Thank you for help.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by GussJ, 03-04-2020, 03:11 PM
                          11 responses
                          3,229 views
                          0 likes
                          Last Post xiinteractive  
                          Started by andrewtrades, Today, 04:57 PM
                          1 response
                          14 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by chbruno, Today, 04:10 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post chbruno
                          by chbruno
                           
                          Started by josh18955, 03-25-2023, 11:16 AM
                          6 responses
                          441 views
                          0 likes
                          Last Post Delerium  
                          Started by FAQtrader, Today, 03:35 PM
                          0 responses
                          12 views
                          0 likes
                          Last Post FAQtrader  
                          Working...
                          X