Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting DrawText

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

    Converting DrawText

    Hi Support and All!

    Could anyone please help me to convert DrawText sample from NT7 to NT8?

    Code:
    if (drawValue){
    				    string newValue = Math.Round(Close[0] + (Close[0]  * (0.5/ 100)),2).ToString();
    				    							
    					DrawLine("Line", true, 0, (Close[0] + (Close[0]  * (0.5/ 100))), -8, (Close[0] + (Close[0]  * (0.5/ 100))), bullTrend, DashStyle.Solid, 1);
    				
    using (Font fontTextFont = new Font(FontFamily.GenericMonospace, 8.0f, FontStyle.Bold))						
    	           {
                        DrawText("Tag", true, "Value", -14, (Close[0] - (Close[0]  * (0.5/ 100))), 0, bullTrend, fontTextFont, StringAlignment.Near, Color.Empty, Color.Empty, 0);Color.Empty, 0);
    
                        DrawText("Tag, true, newValue, -8, (Close[0] + (Close[0]  * (0.5/ 100))), 0, bullTrend, fontTextFont, StringAlignment.Near, Color.Empty, Color.Empty, 0);
    	            }
                }

    #2
    Hi,

    The DrawText in NT8 is relatively simple:

    Code:
    Draw.Text(this, textIDstring, true, stringToDraw, bar time at which to draw, y, yPixelOffset, textBrush, textFont, TextAlignment.Center, null, null, 0);
    So your statement:
    Code:
    DrawText("Tag", true, "Value", -14, (Close[0] - (Close[0]  * (0.5/ 100))), 0, bullTrend, fontTextFont, StringAlignment.Near, Color.Empty, Color.Empty, 0);Color.Empty, 0);
    would translate as:
    Code:
    Draw.Text(this, "Tag", true, "Value", 14, (Close[0] - (Close[0]  * (0.5/ 100))), 0, bullTrend, fontTextFont, TextAlignment.Left, null,  null, 0);
    I am not sure where you are having the issue.

    BTW: You can set the font as:
    Code:
    textFont = new Gui.Tools.SimpleFont("Arial", 12) { Size = Font_Size, Bold = true } ?? ChartControl.Properties.LabelFont;
    Last edited by Zeos6; 06-05-2018, 07:48 AM.

    Comment


      #3
      Hello outsource,
      Thanks for your post.

      This snippet would not take much to convert. You just need to change the Draw methods and how the font is being set. For example. the following is how you would convert DrawLine() to Draw.Line().
      Code:
      Draw.Line(this, "Line", true, 0, (Close[0] + (Close[0]  * (0.5/ 100))), 8, (Close[0] + (Close[0]  * (0.5/ 100))), bullTrend, DashStyleHelper.Solid, 1);
      I am including some help guide documentation below that you will find useful for the rest of this conversion.

      Additionally, while there is no step-by-step guide that will show you how to do so, you would be well served by looking through the code-breaking changes from NT7 > NT8, as this will detail what other parts of your scripts will need to be changed to be in compliance with NT8's under the hood changes.
      NinjaTrader 8 - Code Breaking Changes

      Help Guide - Draw.Line()
      Help Guide - Draw.Text()
      Help Guide - SimpleFont
      Help Guide - Working with Brushes

      Let me know if you have any questions. I will leave this post open for anyone else that would like to provide assistance as well.
      Josh G.NinjaTrader Customer Service

      Comment


        #4
        Thanks for your replies!

        What about ToString sample, does it remain the same?

        I need that ToString property to draw the value.

        Comment


          #5
          I believe ToString() will behave the same way as it did in NT7, so no change is needed there.
          Josh G.NinjaTrader Customer Service

          Comment


            #6
            It does. And if you don't like its output, you can always override it with your own version.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            670 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X