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 NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X