Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing Draw.Text color (dynamically maybe)

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

    Changing Draw.Text color (dynamically maybe)

    Hi so I am writing an indicator that displays text to the chart, and on light mode its working properly as the text is rendering as black text. However if I switch to dark mode the text is invisible because it is still black text...

    I know we can see the current theme with:
    Code:
     NinjaTrader.Core.Globals.GeneralOptions.Skin
    And this is my current draw code:
    Code:
     Draw.Text(this, "myText", "black Text", -4, High[0] - ((High[0] - Low[0]) / 2));
    How do I edit the Draw.Text color? Any code examples or help would be greatly appreciated.

    Also followup: If anyone can explain how a user could change this in indicator options that would be awesome.

    #2
    I was able to find a solution and will post my code here incase anyone else need help on this.

    In your indicator SetDefaults you can define a brush to hold the text color:
    Code:
    TextColor = Brushes.Black;
    And have the user choose the text color in properties:
    Code:
        [NinjaScriptProperty]
            [XmlIgnore]
            [Display(Name = "Text Color", Description = "Color of text", Order = 12, GroupName = "Colors")]
            public Brush TextColor
            { get; set; }​
    Also we want two more variables for my example, one to change font options (also goes in the SetDefaults)
    Code:
    TextFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12);
    And in our properties we make them able to edit the font style:

    Code:
        [Display(Name = "Font, size, type, style",
                Description = "Select font, style, size to display on chart",
                GroupName = "Text",
                Order = 1)]
            public Gui.Tools.SimpleFont TextFont
            { get; set; }​
    Finally for our actual draw method:
    Code:
    Brush empty = Brushes.Transparent;
    // See Draw.Text in your IDE for all argument types.
    Draw.Text(this, "yourLabel", false, "yourText", 0, High[0] - ((High[0] - Low[0]) / 2), 0, TextColor, TextFont, TextAlignment.Center, empty, empty, 0);
    Ill try to check this thread if anyone needs more assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    156 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    90 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    138 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    130 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    107 views
    0 likes
    Last Post CarlTrading  
    Working...
    X