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

Custom Color Properties

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

    Custom Color Properties

    Hello,

    I am trying to develop a custom indicator that is fully customizable. The one thing I am having troubles with is the colors properties. I want to be able to pick custom colors and widths and what not for some verticle lines and while I was able to get everything plotted manually within the script, I want to be able to adjust it from the properties box before adding it to a chart. I have attached a copy of the code in hopes someone will be able to help me figure out what I am missing. I hope this all makes sense if you do not understand something please feel free to reply and I will respond ASAP!

    Thank You!

    Connor.
    Attached Files

    #2
    Connor. I'll give you a start. You want to create a generic placeholder for the values you want to be able to set in the properties box. Let's take the width of the lines. In your code it shows a width of "2". Replace the 2 with for example wline e.g.

    Draw.VerticalLine(this, "EMACross", 0, Brushes.DarkRed, DashStyleHelper.Solid, wline);

    Now you need to add two things to your code:

    1. Declare a new private int:

    private int wline =2; // the 2 here would be the default setting

    2. At the bottom in the
    #region Properties add:

    [Description("Chosen value for width of lines.")]
    [Category("Parameters")]
    [Gui.Design.DisplayNameAttribute("Width of Lines")]
    public int Wline //Note the capital letter
    {
    get { return wline; }
    set { wline = Math.Max(1, value); }
    }

    It's similar for the colors but I am not used to brushes so perhaps someone else can help you with those.

    sandman

    Comment


      #3
      Hi Connor,
      First of all I would try to use the NT8 indicator wizard to write/convert any indicators of my choice, makes it much more easier. It would automatically create properties and associated serializations (if any) and takes out the hassle. Remember, the Brush Properties MUST be Serialized. Let's make an example out of your code.

      // Set 1
      if ((CrossAbove(EMA1, EMA2, 1)) || (CrossBelow(EMA1, EMA2, 1)))
      {
      Draw.VerticalLine(this, "EMACross", 0, Brushes.DarkRed, DashStyleHelper.Solid, 2);
      }

      First of Define a Property with a Brush Type, as follows:

      public Brush ColorCrossDown
      { get; set; }

      Serialize it

      [Browsable(false)]
      public string ColorCrossDownSerializable
      {
      get { return Serialize.BrushToString(ColorCrossDown); }
      set { ColorCrossDown = Serialize.StringToBrush(value); }
      }

      Initialize Your Default Color in State == State.Defaults

      if (State == State.Defaults)
      {
      ColorCrossDown = Brushes.DarkRed;
      }

      Now use ColorCrossDown in your code

      // Set 1
      if ((CrossAbove(EMA1, EMA2, 1)) || (CrossBelow(EMA1, EMA2, 1)))
      {
      Draw.VerticalLine(this, "EMACross", 0, ColorCrossDown, DashStyleHelper.Solid, 2);
      }

      You should now be able to select different colors for ColorCrossDown in the indicator UI.

      Hope it helps
      Cheers,
      Mukaddim
      Last edited by Mukaddim; 09-19-2018, 09:28 AM.

      Comment


        #4
        Hello Connor,

        Thanks for your post.

        Members sandman and Mukaddim have provided solutions for you.

        Here are help guide references for further information:

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello Connor,

          Thanks for your post.

          Members sandman and Mukaddim have provided solutions for you.

          Here are help guide references for further information:

          https://ninjatrader.com/support/help...lor_inputs.htm
          I first want to thank everybody for their help, however, I am getting error CS0103 that the name does not exist in the current context. I have followed everyone's steps including the "User-Definable Color Inputs" and am still getting this error. What am I doing wrong?
          Attached Files

          Comment


            #6
            Hello Connor,

            Thanks for your reply.

            Using "UpTrend" as the example (meaning you have others that are similar to fix), the error message is "The name "UPTrend" does not exist in the current context. This means that it has not been declared.

            Looking at the code I see, in state defaults: UPTrend = Brushes.PaleGreen; which will assign a default color to UpTrend but does not create the brush needed.

            In the properties section though, you do not have UPTrend defined, all I see is:

            [Browsable(false)]
            [XmlIgnore]
            [Category("Colors")]
            public string UPTrendSerializable
            {
            get { return Serialize.BrushToString(UPTrend); }
            set { UPTrend = Serialize.StringToBrush(value); }
            }

            the above is only creating a string called UPTrendSerializeable which is needed to properly save the chosen color. You need to declare the brush UpTrend and serialize as you have done but arranged like:


            [XmlIgnore]
            [Category("Colors")]
            public Brush UpTrend
            { get; set; }

            [Browsable(false)]
            public string UPTrendSerializable
            {
            get { return Serialize.BrushToString(UPTrend); }
            set { UPTrend = Serialize.StringToBrush(value); }
            }
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Paul View Post
              Hello Connor,

              Thanks for your reply.

              Using "UpTrend" as the example (meaning you have others that are similar to fix), the error message is "The name "UPTrend" does not exist in the current context. This means that it has not been declared.

              Looking at the code I see, in state defaults: UPTrend = Brushes.PaleGreen; which will assign a default color to UpTrend but does not create the brush needed.

              In the properties section though, you do not have UPTrend defined, all I see is:

              [Browsable(false)]
              [XmlIgnore]
              [Category("Colors")]
              public string UPTrendSerializable
              {
              get { return Serialize.BrushToString(UPTrend); }
              set { UPTrend = Serialize.StringToBrush(value); }
              }

              the above is only creating a string called UPTrendSerializeable which is needed to properly save the chosen color. You need to declare the brush UpTrend and serialize as you have done but arranged like:


              [XmlIgnore]
              [Category("Colors")]
              public Brush UpTrend
              { get; set; }

              [Browsable(false)]
              public string UPTrendSerializable
              {
              get { return Serialize.BrushToString(UPTrend); }
              set { UPTrend = Serialize.StringToBrush(value); }
              }
              I don't mean to be a pain, and you guys have been extremely helpful, but it is still not customizable. There are no errors because everything should be good, but it still only picks the default no matter what color I choose. I even tried adding // in front of the SetDefaults brushes so there would theoretically be no default color and it still did not work. Again, I am sorry for any inconvenience, headaches, anything, but I just do not understand what the problem is

              *Also, a side note. The indicator only displays 1 line. Meaning, when you scroll back through the chart history the plots do not save and you cannot see any previous vertical lines. I have never seen this before. Do you know why that happens now?*

              Thanks again for everything! I really appreciate all you guys do!
              Attached Files

              Comment


                #8
                Hi Connor,
                Since the indicator has no custom series, the code block in STATE.DATALOADED should be in STATE.DEFAULT.

                Chrers!

                Comment


                  #9
                  Hello Conner,

                  Thanks for your reply.

                  Your code still contains errors, or at least the version you last posted does and those need to be resolved first.

                  To see all of the occurrences of a draw object, you need to make the tag name unique. The easy way to do that is to add the CurrentBar, for example, change: Draw.VerticalLine(this, "EMACross", 0, ColorEMACross, DashStyleHelper.Solid, 2);

                  to:

                  Draw.VerticalLine(this, "EMACross"+CurrentBar, 0, ColorEMACross, DashStyleHelper.Solid, 2);
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    I FINALLY figured it out. Thank you all so much! It took bits and pieces from what everyone had said, but I was finally able to get what I wanted. Thanks again!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by BarzTrading, Today, 07:25 AM
                    2 responses
                    23 views
                    1 like
                    Last Post BarzTrading  
                    Started by devatechnologies, 04-14-2024, 02:58 PM
                    3 responses
                    20 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by tkaboris, Today, 08:01 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post tkaboris  
                    Started by EB Worx, 04-04-2023, 02:34 AM
                    7 responses
                    163 views
                    0 likes
                    Last Post VFI26
                    by VFI26
                     
                    Started by Mizzouman1, Today, 07:35 AM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X