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 according to bar width

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

    change font size according to bar width

    is that possible?

    Best regards
    Thomas

    #2
    Hello Thomas,

    Thanks for your post.

    Are you referring to changing the font size of the text of a drawing object, such as Draw.Text(), so that the font size is equal to the bar width?

    If so, this could be possible by using ChartControl.BarWidth to get the width of the bars and save that value to a double variable.

    double barWidth = ChartControl.BarWidth;

    Then, you could use the Draw.Text() syntax that allows you to specify a SimpleFont argument. You would use the barWidth variable when specifying the Size of your SimpleFont.

    Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, int barsAgo, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity)

    The code might look something like this:

    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = barWidth, Bold = true };

    Draw.Text(this, "myTag", false, "Hi There!", 0, Low[0], 5, Brushes.Pink, myFont, TextAlignment.Center, Brushes.Transparent, null, 1);


    See the help guide documentation below for more information and sample code.

    BarWidth: https://ninjatrader.com/support/help...l_barwidth.htm
    Draw.Text: https://ninjatrader.com/support/help.../draw_text.htm
    SimpleFont: https://ninjatrader.com/support/help...font_class.htm

    Let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      many thanks, found the error

      my code was:
      if (ChartControl.BarWidth==2) myFontW.Size = 20;
      if (ChartControl.BarWidth==3) myFontW.Size = 30;
      if (ChartControl.BarWidth==4) myFontW.Size = 40;

      but should have been:
      if (ChartControl.BarWidth>1.9) myFontW.Size = 20;
      if (ChartControl.BarWidth>2.9) myFontW.Size = 30;
      if (ChartControl.BarWidth>3.9) myFontW.Size = 40;

      Comment


        #4
        Hi Brandon,
        I also wanted to adjust the font text size dynamically with the change in bar width. Tried your suggestion
        HTML Code:
        double barWidth = ChartControl.BarWidth;
        NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = barWidth, Bold = true };
        but keep getting the following error : An object reference is required for the non-static field, method, or property 'NinjaTrader.Gui.Chart.ChartControl.BarWidth.get"

        I am not sure what the issue is. Request assistance.

        Comment


          #5
          Hello kashter,

          Thanks for your note.

          Are you calling this code within the OnBarUpdate() method of an indicator?

          Please see the attached example indicator demonstrating how to set the font size of the Draw.Text() method to use the same value as the chart's BarWidth.

          Let me know if I may assist further.
          Attached Files
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Thank you Brandon, much appreciated.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            26 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 02-22-2024, 01:11 AM
            5 responses
            32 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 04-23-2024, 09:53 PM
            2 responses
            49 views
            0 likes
            Last Post wzgy0920  
            Started by Kensonprib, 04-28-2021, 10:11 AM
            5 responses
            193 views
            0 likes
            Last Post Hasadafa  
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,235 views
            0 likes
            Last Post xiinteractive  
            Working...
            X