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

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 Aviram Y, Today, 05:29 AM
            0 responses
            2 views
            0 likes
            Last Post Aviram Y  
            Started by quantismo, 04-17-2024, 05:13 PM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            34 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cls71, Today, 04:45 AM
            0 responses
            6 views
            0 likes
            Last Post cls71
            by cls71
             
            Started by mjairg, 07-20-2023, 11:57 PM
            3 responses
            216 views
            1 like
            Last Post PaulMohn  
            Working...
            X