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 bortz, 11-06-2023, 08:04 AM
            47 responses
            1,607 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            15 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X