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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X