Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change Font Size

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

    Change Font Size

    I have a strategy that uses DrawText() to print text on the chart:

    DrawText("HighPrice", "High Entry is "+(Low[0]+TickSize*9)+ " SELL",18,Low[0]+TickSize*10,Color.White);

    What I would like to do is change the type face and point size of the font. I have tried changing the above code line follow the DrawText() syntax below, but I don't know how to format the "Font font"

    The following is the DrawText() syntax:

    DrawText(string tag, bool autoScale, string text, int barsAgo, double y, int yPixelOffset, Color textColor, Font font, StringAlignment alignment, Color outlineColor, Color backColor, int opacity)

    What would I change "Font font" to, to change the type to 14pt Helvetica Bold, for example?

    Thanks

    #2
    ghunt, there is actually a reference sample that goes over exactly what you're looking for. Please see the 'changing fonts for draw objects' page for further information, but the code you want would look something like this:
    Code:
    private Font helveticaFont = new Font("Helvetica", 14);
    AustinNinjaTrader Customer Service

    Comment


      #3
      Austin,

      Thanks for your quick reply. I created a new Font variable:

      private Font hFont = new Font("Helvetica", 14);

      and put it into the DrawText() line - it works just I had planned! Thanks.

      Comment


        #4
        Originally posted by ghunt View Post
        Austin,

        Thanks for your quick reply. I created a new Font variable:

        private Font hFont = new Font("Helvetica", 14);

        and put it into the DrawText() line - it works just I had planned! Thanks.
        Can I ask where 'exactly' you place the statement? Does it go before Initialize(), between Initialize() & OnBarUpdate(), or after OnBarUpdate()? I have tried several locations with no such luck. When I make the variable private and use the variable in my DrawTextFixed() method, it creates numerous errors that seem to extend the number of parameters that DrawTextFixed() is looking for. Any help would be greatly appreciated.

        Comment


          #5
          Originally posted by Joe_T View Post
          Can I ask where 'exactly' you place the statement? Does it go before Initialize(), between Initialize() & OnBarUpdate(), or after OnBarUpdate()? I have tried several locations with no such luck. When I make the variable private and use the variable in my DrawTextFixed() method, it creates numerous errors that seem to extend the number of parameters that DrawTextFixed() is looking for. Any help would be greatly appreciated.
          It would go in the variable declaration section, typically before initialize, startup and onbarupdate. So with the original example, something like:

          #region Variables
          private Font hFont = new Font("Helvetica", 14);
          #Endregion

          protected override void Initialize()
          {
          }

          protected override void OnStartUp()
          {
          }

          protected override void OnBarUpdate()
          {

          DrawTextFixed(.......hFont...) (hFont represents the new font to use)
          }

          Comment


            #6
            Ok. I see the private statement goes before the Initialize() section. What was tripping me up is the DrawTextFixed() method has either of "two" different syntax. If the Font variable is used, then the second form of the syntax 'must' be used in which each and every of the draw parameters must be specified. It works fine now & thanks for the help below.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X