Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Kaledus, Today, 01:29 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frankthearm, Yesterday, 09:08 AM
      13 responses
      45 views
      0 likes
      Last Post frankthearm  
      Started by PaulMohn, Today, 12:36 PM
      2 responses
      16 views
      0 likes
      Last Post PaulMohn  
      Started by Conceptzx, 10-11-2022, 06:38 AM
      2 responses
      55 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Started by yertle, Yesterday, 08:38 AM
      8 responses
      37 views
      0 likes
      Last Post ryjoga
      by ryjoga
       
      Working...
      X