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 CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      167 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      88 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      128 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      208 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      185 views
      0 likes
      Last Post CarlTrading  
      Working...
      X