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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      63 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      35 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      54 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      61 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      48 views
      0 likes
      Last Post CarlTrading  
      Working...
      X