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

Passing color as string to custom DrawDiamond() method

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

    Passing color as string to custom DrawDiamond() method

    In developing a new indicator, I need to create a generalized method that simply draws diamond via DrawDiamond().

    I like to pass color as string, e.g. "Blue" to this method, but DrawDiamond() requires 'Color' object. I don't know how to assign a string color to Color object. Can someone please help. I know this is more of a c# question, but I appreciate help in any case
    Last edited by stevenev1; 02-25-2017, 11:06 AM.

    #2
    Hello,

    Thank you for the question.

    Do you specifically need a string or would passing the Color object work as well?

    Also, you are listing NT7 syntax but we are in the NT8 forum, can you confirm is this for NT7 or NT8?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse, thank you very much for your reply. I don't mind passing a color object, etc. to the method, as long as the method can be parametrised and I don't have to write a new line for each color. I have to do a lot better than this not-good implementation of mine

      protected void diamond( string color ) {

      string myTag = "tag-" + color + CurrentBar.ToString();

      if ( color == "red" )
      Draw.Diamond(this, myTag, true, 0, Low[0] - TickSize, Brushes.Red);

      if ( color == "green" )
      Draw.Diamond(this, myTag, true, 0, Low[0] - TickSize, Brushes.Green);

      }

      NT8

      Comment


        #4
        Hello,

        Thank you for the reply.

        In this case, you could use the following syntax:

        Code:
        private void Diamond( Brush color ) 
        {
            string myTag = "tag-" + color.ToString() + CurrentBar.ToString(); 
            Draw.Diamond(this, myTag, true, 0, Low[0] - TickSize, color); 
        }
        
        protected override void OnBarUpdate()
        {
        	Diamond(Brushes.Red);
        }
        If you wanted to make this selectable, you could see this example of making color inputs http://ninjatrader.com/support/forum...ead.php?t=4977

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Should that not be
          Code:
          private void Diamond( Brush color ) ...

          Comment


            #6
            I also found a way to do this, by using a color string. If using this approach, need to make sure to properly capitalize the colors, e.g. "Blue" and not "blue". I think using the object is much better in any case

            ref: http://stackoverflow.com/questions/3...ame-in-c-sharp

            protected void diamond( string myColor ) {

            Type t = typeof(Brushes);
            Brush b = (Brush)t.GetProperty( myColor ).GetValue(null, null);

            string myTag = "tag-" + myColor + CurrentBar.ToString(); // ( CurrentBar.ToString );

            Draw.Diamond(this, myTag, true, 0, Low[0] - TickSize, b);

            }

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by yertle, Yesterday, 08:38 AM
            7 responses
            28 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by bmartz, 03-12-2024, 06:12 AM
            2 responses
            21 views
            0 likes
            Last Post bmartz
            by bmartz
             
            Started by funk10101, Today, 12:02 AM
            0 responses
            4 views
            0 likes
            Last Post funk10101  
            Started by gravdigaz6, Yesterday, 11:40 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by MarianApalaghiei, Yesterday, 10:49 PM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X