Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Text Feature

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

    Draw Text Feature

    I have found a series of code library items as well as some forum items on this but honestly the library instruction and code sets are ambiguous & generalized. Drawing text is obviously quite simple but throwing in the usual suspects to get what I want is not working, i.e. I'm being an idiot ...

    Objective:
    Draw text in the top right corner of a certain color and font size.



    Draw.TextFixed(this, @"MyObject",@"My Text", TextPosition.TopRight,);

    To finish this, I'm not finding the correct syntax for both color and font size. What I'm after is to increase the font size from the default settings and display in Cyan Color.

    Continuing with this for example threw an argument error:

    Draw.TextFixed(this, @"MyObject",@"My Text", TextPosition.TopRight, Brushes.Cyan);


    Goal:
    My Text



    Thanx
    JM

    #2
    Hello johnMoss,

    Thanks for your post.

    To specify a font size for your drawing object you will need to use a SimpleFont and the Draw.TextFixed() overload that lets you specify a SimpleFont parameter.

    Draw.TextFixed(NinjaScriptBase owner, string tag, string text, TextPosition textPosition, Brush textBrush, SimpleFont font, Brush outlineBrush, Brush areaBrush, int areaOpacity)

    For example, the code might look something like this.
    Code:
    // create custom Courier New, make it big and bold
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 50, Bold = true };​
    
    // draw text on chart using SimpleFont myFont
    Draw.TextFixed(this, "MyObject", "My Text", TextPosition.TopRight, Brushes.Cyan, myFont, null, null, 100);
    See the help guide documentation below for more information.

    Draw.TextFixed: https://ninjatrader.com/support/help..._textfixed.htm
    SimpleFont: https://ninjatrader.com/support/help...font_class.htm

    Please let me know if you have further questions on this topic.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Draw.TextFixed(this, "ATR", "ATR: " + Math.Round(atr, RoundNumbersTo), TextPosition.TopRight, Brushes.White, new NinjaTrader.Gui.Tools.SimpleFont("Arial", 16), Brushes.Yellow, Brushes.Yellow, 0);
      Draw.TextFixed(this, "Target", "Target: " + Math.Round(target, RoundNumbersTo), TextPosition.TopRight, Brushes.White, new NinjaTrader.Gui.Tools.SimpleFont("Arial", 16), Brushes.Green, Brushes.Green, 20);
      Draw.TextFixed(this, "Stop", "Stop: " + Math.Round(stop, RoundNumbersTo), TextPosition.TopRight, Brushes.White, new NinjaTrader.Gui.Tools.SimpleFont("Arial", 16), Brushes.Red, Brushes.Red, 40);


      I am converting a Trading View Pine Script to display ATR Target and Stop in TopRight Position of chart. I do see the boxes in the upper right corner but they are coving each other.
      Stop is on top of the others.

      How do I place them across the top edge of the chart

      Thanks

      Comment


        #4
        Hello DTSSTS,

        Thanks for your notes.

        There are no means available for drawing the text next to each other horizontally when using the Draw.TextFixed() method.

        You could use escape characters (\n) with Draw.TextFixed() to create a new line in the text and two (or more) which would draw each line of text below the other.

        See the example script, DrawTextFixedExample, on this forum thread which demonstrates this concept: https://forum.ninjatrader.com/forum/...403#post838403

        If you want to draw text across the top of the chart horizontally, you would have to use SharpDX in OnRender() to custom render objects on the chart.

        The SampleCustomRender script that comes default with NinjaTrader 8 could be viewed to gain an understanding of how to use SharpDX to custom render chart objects. To view this script, open a New > NinjaScript Editor window, open the Indicators folder, and double-click on the SampleCustomRender file.

        See the help guide pages below for more information.

        OnRender(): https://ninjatrader.com/support/help...htsub=OnRender
        RenderTarget.DrawText(): https://ninjatrader.com/support/help...t_drawtext.htm
        Using SharpDX for Custom Chart Rendering: https://ninjatrader.com/support/help..._rendering.htm
        Last edited by NinjaTrader_BrandonH; 07-11-2023, 08:22 AM.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          See the example script, DrawTextFixedExample, on this forum thread which demonstrates this concept:

          where would i find this

          Thanks

          Comment


            #6
            Hello DTSSTS,

            Thanks for your note.

            Please see the link I shared on post # 4 to see the DrawTextFixedExample script. I have also added the link below.

            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              thanks sorry when I read the post the last line of post was

              See the example script, DrawTextFixedExample, on this forum thread which demonstrates this concept:

              with nothing underneath

              Comment


                #8
                Yeah long since resolved on this one but thank you

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                558 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                324 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                546 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                547 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X