Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to change Font in OnRender - TextLayout - in BarTimer indicator

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

    How to change Font in OnRender - TextLayout - in BarTimer indicator

    How does one change the color, font size in the BarTimer indicator?

    regards,
    taddypole...
    Attached Files

    #2
    Hello Taddypole,

    Thank you for your inquiry.

    You would be able to change the font and font size of the BarTimer indicator by modifying the already existing textFormat variable.

    Here's an example to change the font to 12 point Times New Roman:
    Code:
    NinjaTrader.Gui.Tools.SimpleFont sf = new NinjaTrader.Gui.Tools.SimpleFont("Times New Roman", 12);
    TextFormat textFormat = sf.ToDirectWriteTextFormat();
    More information about the SimpleFont class can be found here: http://ninjatrader.com/support/helpG...font_class.htm

    To modify the color, you'll want to modify the existing RenderTarget.DrawTextLayout() method call:
    Code:
    RenderTarget.DrawTextLayout(location, textLayout, Brushes.[Color].ToDxBrush(RenderTarget), DrawTextOptions.NoSnap);
    You'll want to replace [Color] with the color brush you want.

    You can find the various available colors here: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thank you Zachary,

      I tried adding the code you provided but didn't know exactly where to put it. I show where I modified the code but it didn't change the font at all. See attached....

      regards,
      taddypole...
      Attached Files

      Comment


        #4
        Hello Taddypole,

        It seems that you have entered the code correctly from the screenshot you have provided me.

        Please ensure that you are loading the correct bar timer to your chart. Have you modified your BarTimerTest's Name in OnStateChange()? If not, the name will be the same as the default BarTimer's.

        If you are still having an issue, please remove the indicator from the chart and insert it back in.

        If there are still issues, please attach your script's .CS file so I may investigate further.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Please document TextFormat for correct use then

          Originally posted by NinjaTrader_ZacharyG View Post
          Hello Taddypole,

          Thank you for your inquiry.

          You would be able to change the font and font size of the BarTimer indicator by modifying the already existing textFormat variable.

          Here's an example to change the font to 12 point Times New Roman:
          Code:
          NinjaTrader.Gui.Tools.SimpleFont sf = new NinjaTrader.Gui.Tools.SimpleFont("Times New Roman", 12);
          TextFormat textFormat = sf.ToDirectWriteTextFormat();
          More information about the SimpleFont class can be found here: http://ninjatrader.com/support/helpG...font_class.htm

          To modify the color, you'll want to modify the existing RenderTarget.DrawTextLayout() method call:
          Code:
          RenderTarget.DrawTextLayout(location, textLayout, Brushes.[Color].ToDxBrush(RenderTarget), DrawTextOptions.NoSnap);
          You'll want to replace [Color] with the color brush you want.

          You can find the various available colors here: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

          Please, let us know if we may be of further assistance.
          Maybe we should have the use of TextFormat in the documentation? No?

          Comment


            #6
            Hello koganam,

            TextFormat is a SharpDX class: http://sharpdx.org/documentation/api...ite-textformat
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ZacharyG View Post
              Hello koganam,

              TextFormat is a SharpDX class: http://sharpdx.org/documentation/api...ite-textformat
              Ah thanks. Grrr . That is some of the most obtuse documentation that I have ever had the "mispleasure" (yes, I know that that is not really a word, but "displeasure" does not quite cut it here, so I have taken the liberty of coining my own word ), of having to wade through. Extend congrats to your team for having the fortitude to read and understand such sparse documentation.
              Last edited by koganam; 10-27-2015, 10:37 AM.

              Comment


                #8
                Originally posted by NinjaTrader_ZacharyG View Post
                Hello Taddypole,

                Please ensure that you are loading the correct bar timer to your chart. Have you modified your BarTimerTest's Name in OnStateChange()? If not, the name will be the same as the default BarTimer's.
                Thank you Zachary,

                Was focusing so much on the code that I forgot the basics...

                regards,
                taddypole...

                Comment


                  #9
                  how give user ability to set the color? can't get it to work

                  This thread was helpful. So I added the ability for the user to change the font size -- and it works like a charm. Then I added a variable for color ... and I get an error that I don't understand. Any one out there who can help with this?

                  Two variables were added to State.Defaults:
                  TextSize = 12;
                  TextColor = Brushes.Wheat;

                  The RenderTarget has the color variable where the Brushes.[Color] is supposed to go:
                  RenderTarget.DrawTextLayout(location, textLayout, TextColor.ToDxBrush(RenderTarget), DrawTextOptions.NoSnap);

                  And a Properties section was added:
                  #region Properties
                  [Range(1, int.MaxValue)]
                  [NinjaScriptProperty]
                  [Display(Name="FontSize", Description="The font size for the text.", GroupName="Parameters")]
                  public int TextSize
                  { get; set; }

                  [XmlIgnore]
                  [Display(Name="TextColor", Description="", GroupName="Parameters")]
                  public Brush TextColor
                  { get; set; }

                  [Browsable(false)]
                  public string TextColorSerializable
                  {
                  get { return Serialize.BrushToString(TextColor); }
                  set { TextColor = Serialize.StringToBrush(value); }
                  }
                  #endregion

                  And, the error generated is for the "public Brush TextColor" line of code:
                  'Brush' is an ambiguous reference between 'System.Windows.Media.Brush' and 'SharpDX.Direct2D1.Brush'

                  What on earth is it telling me? The code I used for the color variable "TextColor" was copied out of a script in which it works perfectly. What am I missing?

                  Thanks,

                  Mark

                  Comment


                    #10
                    Hello Mark,

                    Thank you for writing in.

                    Does your script have a using statement referring to SharpDX.Direct2D1?

                    If this is the case, this is why the conflict is occurring; both namespaces contain a definition for Brush.

                    You will want to use the fully qualified name, System.Windows.Media.Brush or remove the using statement pertaining to SharpDX.Direct2D1 if your script is not using it.

                    Code:
                    public System.Windows.Media.Brush TextColor
                    { get; set; }
                    Please, let us know if we may be of further assistance.
                    Zachary G.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by yertle, Today, 08:38 AM
                    5 responses
                    13 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by frankthearm, Today, 09:08 AM
                    2 responses
                    4 views
                    0 likes
                    Last Post frankthearm  
                    Started by adeelshahzad, Today, 03:54 AM
                    3 responses
                    16 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by bill2023, Yesterday, 08:51 AM
                    6 responses
                    27 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
                    80 responses
                    19,667 views
                    5 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X