Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I set the size of my font

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

    How do I set the size of my font

    Hi

    I have modified an indicator that has the following property

    Code:
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Segoe UI", 24) { Size = 30, Bold = true };    /// Sets myFont
    I have got a property to chose the font and size in my indicator

    FS = Font Size = 30


    But when I substitute (FS) for the 30 in the above statement like this

    Code:
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Segoe UI", 24) { Size = (FS), Bold = true };    /// Sets myFont
    I get the following error - " A field initializer cannot reference the non-static field, method, or property 'NinjaTrader.NinjaScript.Indicators.FxM.aBarTimer. FS.get'

    Ay help would be appreciated

    John

    #2
    Hello johnvnwp,

    If you are trying to control the fonts size that should be the 24 in what you provided.

    Code:
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Segoe UI", [B]30[/B]) {  Bold = true }; /// Sets myFont
    If you for some reason need to control the Size property you have shown you would need to use a double :

    Code:
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Segoe UI", 24) { Size = [B]30[/B], Bold = true }; /// Sets myFont
    The error message you provided seems unrelated to this line of syntax

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse - thanks for the fast reply

      This is how I have set up the FS variable so that the user can change the size.

      Code:
       FS                    = 30;
      Code:
      // [NinjaScriptProperty]
      [Display(Name="Timer Size", Description="Size of Timer Block", Order=1, GroupName="Font")]
      public double FS
      { get; set; }
      My project works perfectly with no errors until I substitute FS for the 30 and then I get that error.

      John

      Comment


        #4
        Hello John,
        If you wish to change the font size from indicator settings you need as below:
        Code:
        [NinjaScriptProperty]
        [Display(Name="Timer Size", Description="Size of Timer Block", Order=1, GroupName="Font")]
        public int FS { get; set; }
        
        In SetDefaults, FS = 24 // set default font size
        
        NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Segoe UI", FS) {Bold = true };
        This will allow you to change the font size.
        Or a rather better way is to have a font family defined so you've full control on font including size, bold, italics & font selection.
        Hope it helps!

        Comment


          #5
          Thanks for the help but I still get the error.
          Under SetDefaults I have the following:

          Code:
          Description = @"Bar Timer attached to Current Price Line.";
          Name = "aBarTimer";
          Calculate = Calculate.OnEachTick;
          IsOverlay = true;
          DisplayInDataBox = false;
          DrawOnPricePanel = true;
          ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
          //Disable this property if your indicator requires custom values that cumulate with each new market data event.
          //See Help Guide for additional information.
          IsSuspendedWhileInactive = true;
          LL = 50;
          LTC = Brushes.Red;
          MTC = Brushes.Maroon;
          HTC = Brushes.Yellow;
          TF = @"Segoe UI";
          FS = 24;
          Bld = true;
          Sz = 30;
          Under Properties I have the following:

          Code:
          // [NinjaScript Property]
          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Opacity", Description="Box Inside Color Opacity", Order=5, GroupName="Settings")]
          public int LL
          { get; set; }
          
          // [NinjaScriptProperty]
          [XmlIgnore]
          [Display(Name="Text Color", Description="Color of Seconds Text ", Order=6, GroupName="Settings")]
          public Brush HTC
          { get; set; }
          
          [Browsable(false)]
          public string HTCSerializable
          {
          get{ return Serialize.BrushToString(HTC); }
          set{ HTC = Serialize.StringToBrush(value); }
          }
          
          [NinjaScriptProperty]
          [Display(Name="Typeface", Description="Typeface", Order=1, GroupName="Font")]
          public string TF
          { get; set; }
          
          [NinjaScriptProperty]
          [Range(6, double.MaxValue)]
          [Display(Name="Font Size", Description="Font Size", Order=2, GroupName="Font")]
          public double FS
          { get; set; }
          
          [NinjaScriptProperty]
          [Display(Name="Timer Size", Description="Size of Timer Block", Order=3, GroupName="Font")]
          public int Sz
          { get; set; }
          
          [NinjaScriptProperty]
          [Display(Name="Bold", Description="Bold", Order=4, GroupName="Font")]
          public bool Bld
          { get; set; }
          Here is the line I use to set the font

          Code:
          NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Segoe UI", 24) { Size = 25, Bold = true };

          I cannot replace the font, point size, size or Bold attribute with the above variables without getting the same error

          eg If I do this
          Code:
          NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont(TF, (FS)) { Size = Sz, Bold = true };
          then I get the error

          " A field initializer cannot reference the non-static field, method, or property 'NinjaTrader.NinjaScript.Indicators.FxM.aBarTimer. FS.get'

          If I take out the variables then it works but then my users can't change the font size or type.

          I am using this code in other places and it works fine

          eg

          Code:
          Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.BarTimerTimeBasedError, TextPosition.BottomRight, LTC,new NinjaTrader.Gui.Tools.SimpleFont(TF,(FS)), LTC, MTC, 0);
          No errors with this line

          So I'm at a loss

          Comment


            #6
            Can you share your script so I can fix it for you.

            Comment


              #7
              That would be awsome - thanks
              Attached Files

              Comment


                #8
                Check this out!
                I've commented what is not required, you can clean up accordingly.
                Now you can find "My Font" to adjust the font & this only font is used in all instances which you can control from indicator settings. You can make further changes as required.
                Attached Files

                Comment


                  #9
                  Thank You so much s.kinra - you are an absolute lifesaver and this goes above and beyond what I expected

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  606 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  351 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  560 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  561 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X