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

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 usazencort, Today, 01:16 AM
            0 responses
            1 view
            0 likes
            Last Post usazencort  
            Started by kaywai, 09-01-2023, 08:44 PM
            5 responses
            603 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            6 responses
            22 views
            0 likes
            Last Post xiinteractive  
            Started by Pattontje, Yesterday, 02:10 PM
            2 responses
            20 views
            0 likes
            Last Post Pattontje  
            Started by flybuzz, 04-21-2024, 04:07 PM
            17 responses
            230 views
            0 likes
            Last Post TradingLoss  
            Working...
            X