Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to compare colors?

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

    How to compare colors?

    Hi

    I'm writing a strategy that will look at drawing objects on a chart and I would like to compare the color of the drawing object to my options in the strategy to see if they match.

    Even when the colors are the same, my code is saying they do not match.

    e.g.

    Code:
    foreach (DrawingTool draw in DrawObjects.ToList())
    {
        if (draw is DrawingTools.ArrowDown)
        {
            DrawingTools.ArrowDown myArrowDown = draw as DrawingTools.ArrowDown;
    
            if (matchColorBuy && enterBuy)
            {
    
                if (myArrowDown.AreaBrush == colourFormBuy)
                {
                    enterBuy = true;
                    if (showInfo) Print(Time[0] + " " + Instrument.FullName + " Color of drawing object: " + myArrowDown.AreaBrush + " does match Buy Form Color: " + colourFormBuy);
                }
    
                else
                {
                    enterBuy = false;
                    if (showInfo) Print(Time[0] + " " + Instrument.FullName + " Color of drawing object: " + myArrowDown.AreaBrush + " does NOT match Buy Form Color: " + colourFormBuy);
                }
    
            }
        }
    Results in NinjaScript Output of:

    25/07/2020 13:14:00 USDCAD Color of drawing object: #FF008000 does NOT match Buy Form Color: #FF008000
    Doing a search for C# help on comparing colors I saw a lot of info on comparing RGB colors but nothing that helped me understand comparing HEX colors.

    Any ideas?

    Many thanks
    Tim

    #2
    Think I've answered my own question! Needed to add .ToString()

    eg

    if (myArrowDown.AreaBrush.ToString() == colourFormBuy.ToString())

    Comment


      #3
      Hello timcjpfx,

      I don't know what type of object colourFormBuy is, but you may try comparing the Brush.Color.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      89 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X