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

Plotting a line with opacity

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

    Plotting a line with opacity

    I am trying to get a lead line plotted on a chart with opacity so that I can still see the bars and any other indicators underneath.

    I have had no problem plotting back colors with opacity and adjusting the opacity in the Menu Panel by having opacity as a public int.

    But when pasting that code over to the indicator, it sort of works and sort of doesn't. What happens is the line is indeed plotted with opacity. But changing the opacity value in the Menu Panel makes no difference, even though the exact same code works with Back Color opacity.

    The only way I can change the opacity is to go back into the code and change the value in the Variables Menu. So if I change it from 15 - 150 in the Variables menu, the colors harden up, i.e. become much more opaque. But if I change the opacityvalue in the Menu Panel from 15 - 150, nothing happens.

    The Colors display in the drop down menu in argh numbers in the Custom Section whilst at the same time there are menu panel options for changing the color up and color down as specified in the code, which colors are supposed to be the ones for the indicator plots. Obviously I am doing something wrong but I have no idea what.

    Here is some of the code showing what I have written:

    #region Variables
    private int period = 9;
    private double fct = 10; // will be divided by 1000 so that each whole number = .001;
    private Color colorup = Color.Gold;
    private Color colordown = Color.SteelBlue;
    private Color colorside = Color.Lime;
    private int opacityValue = 125;

    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    // Add one plot for every color you wish to use.
    Add(new Plot(new Pen(Color.FromArgb(opacityValue, colorup),7), PlotStyle.Line, "Rising"));
    Add(new Plot(new Pen(Color.FromArgb(opacityValue, colordown),7), PlotStyle.Line, "Falling"));
    Add(new Plot(new Pen(Color.FromArgb(opacityValue, colorside),7), PlotStyle.Line, "Neutral"));

    +++ and in the Properties Section:

    [Description("Colorup")]
    [Category("Visual")]
    [Gui.Design.DisplayName ("ColorUp")]
    public Color Colorup
    {
    get { return colorup; }
    set { colorup = value; }
    }

    [Browsable(false)]
    public string ColorupSerialise
    {
    get { return Gui.Design.SerializableColor.ToString(colorup); }
    set { colorup = Gui.Design.SerializableColor.FromString(value); }
    }
    [Description("Colordown")]
    [Category("Visual")]
    [Gui.Design.DisplayName ("ColorDown")]
    public Color Colordown
    {
    get { return colordown; }
    set { colordown = value; }
    }

    [Browsable(false)]
    public string ColordownSerialise
    {
    get { return Gui.Design.SerializableColor.ToString(colordown); }
    set { colordown = Gui.Design.SerializableColor.FromString(value); }
    }
    [Description("Colordown")]
    [Category("Visual")]
    [Gui.Design.DisplayName ("ColorDown")]
    public Color Colorside
    {
    get { return colorside; }
    set { colorside = value; }
    }

    If I change the Colorup from a blue to a red, nothing happens. It can only be changed in the Plot menu and the Opacity value never makes any difference from the Menu Panel, only from the source code.

    Attached: pic of Menu Panel showing the Color Options and Plot Color options duplicated in two separate series.

    What am I doing wrong here so that I can adjust the Line Opacity in the Menu Panel and get it right easily?
    Attached Files
    Last edited by cclsys; 08-17-2009, 12:44 PM.

    #2
    cclsys, not fully following you - with Color.FromArgb you just create a custom color...different chart paint order options (Z Order) will be supported with NinjaTrader 7 - http://www.ninjatrader.com/webnew/NT7/NinjaTrader7.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      cclsys, was searching for the opacityValue processing in your property section, but couldn't find it.

      Regards
      Ralph

      Comment


        #4
        Ralph, ironic that in putting this together I took out the lines I had from 'Ralph' (no doubt you) from another indicator whose coding I got with your help months ago.

        In response to your question this is all I have in the Property Section viz. colors:

        [Description("Colorup")]
        [Category("Visual")]
        [Gui.Design.DisplayName ("ColorUp")]
        public Color Colorup
        {
        get { return colorup; }
        set { colorup = value; }
        }

        [Browsable(false)]
        public string ColorupSerialise
        {
        get { return Gui.Design.SerializableColor.ToString(colorup); }
        set { colorup = Gui.Design.SerializableColor.FromString(value); }
        }
        [Description("Colordown")]
        [Category("Visual")]
        [Gui.Design.DisplayName ("ColorDown")]
        public Color Colordown
        {
        get { return colordown; }
        set { colordown = value; }
        }

        [Browsable(false)]
        public string ColordownSerialise
        {
        get { return Gui.Design.SerializableColor.ToString(colordown); }
        set { colordown = Gui.Design.SerializableColor.FromString(value); }
        }
        [Description("Colordown")]
        [Category("Visual")]
        [Gui.Design.DisplayName ("ColorDown")]
        public Color Colorside
        {
        get { return colorside; }
        set { colorside = value; }
        }

        [Browsable(false)]
        public string ColorsideSerialise
        {
        get { return Gui.Design.SerializableColor.ToString(colorside); }
        set { colorside = Gui.Design.SerializableColor.FromString(value); }
        }
        [Description("Opacity")]
        [Category("Visual")]
        public int OpacityValue
        {
        get { return opacityValue; } // Ralph: max. opacity is 255 by specification // set { opacityValue = value; }
        set { opacityValue = Math.Max(1, Math.Min(255, value)); }
        //set { opacityValue = value;}
        }

        ++++++++++

        I got the serialising sections from you before. But this time - when applied to a Plot versus a BackColor, it seems to behave differently.

        Again, the coding for the Plots is:

        Add(new Plot(new Pen(Color.FromArgb(opacityValue, colorup),7), PlotStyle.Line, "Rising"));
        Add(new Plot(new Pen(Color.FromArgb(opacityValue, colordown),7), PlotStyle.Line, "Falling"));
        Add(new Plot(new Pen(Color.FromArgb(opacityValue, colorside),7), PlotStyle.Line, "Neutral"));

        +++++++++

        As you can see, the Plot colors are referenced from the colorup, colordown, colorside as further laid out in the Properties Menu, but they cannot be accessed as such in the Menu Panel.

        Now again as to your question viz. 'opacity/value processing': I am not aware of anything else that needs to be done nor what it is exactly that you are referring to.

        If you mean the part with the OpacityValue, then I apologise for not including that the first time. It was there all along but for some reason I did not paste it in.

        In the variables section it goes:

        private Color colorup = Color.Gold;
        private Color colordown = Color.SteelBlue;
        private Color colorside = Color.Lime;
        private int opacityValue = 125;

        Idea: Have I made a mistake in telling the colors to be Color.Gold etc. instead of defining them as argh-type colors in the Variable Section? If so, how is that lingo phrased?

        Thxs.
        Last edited by cclsys; 08-17-2009, 02:36 PM.

        Comment


          #5
          Hi cclsys,

          first of all you should attach attribute [XmlIgnore()] to all of your color properties (Colorup,...) because we don't want them to show up in the xml file, they wouldn't be serialised correctly anyway. The properties for serialisation (ColorupSerialise,...) are designed correctly. I am not saying, it is not working this way, but I would change it to be on the save side.

          I asked you to show the opacity property because I wanted to see if there is something unusual, but it is not. I haven't coded plot dataseries with variable opacity by myself and can't report from own experience. And I can't see an obvious mistake. I would propose to insert runtime debug statements into the code. Put one into the opacity statement:

          public int OpacityValue
          {
          ...
          set
          {
          opacityValue = Math.Max(1, Math.Min(255, value));
          Print("Property opacity: " + opacityValue);
          }
          }

          And another in front of the initialisation:

          Print("Add new plot, opacity: " + opacityValue);
          Add(new Plot(new Pen(Color.FromArgb(opacityValue, colorup),7), PlotStyle.Line, "Rising"));

          Open the output window before starting debugging. This way it should be possible, to see if the opacity is handed over correctly.

          Regards
          Ralph

          Comment


            #6
            I put in the xml ignores everywhere and they compile. No change.

            I put in the Prints as you suggested and got the following:

            First it says 125 (which is what I have in the Variables as the default option).
            Then in series it said 11 each time which is what I put into the Menu Panel.

            To be precise
            Property opacity: 11
            Add new Plot, opacity: 11.

            Why there were only 4 occurrences of each I have no idea, maybe because this is not live action?

            Comment


              #7
              I think the clue to what is wrong is in the opacity.pic I pasted in above showing that for some reason the drop down menus for the Plots co-exist with lower down menus for the colors. I guess plots always get drop dowm menus of their own. Or is there a command that makes them unavailable for configuration in the Indicator Panel so that the only thing you change in the indicator panel is the Variable-based colors and opacity and if you want to change the lines to dashes etc. you have to do that inside the code?

              After writing the above I had a vague memory of seeing something somewhere and found:

              PlotsConfigurable = false; // Plots are not configurable in the indicator dialog

              That takes the Indicator Configuration (colors, linestyles etc.) out of the Indicator dialog menu so now all that is left are my three colors plus opacityvalue.

              Changing the colors is easy.
              But opacity doesn't change it seems even though there IS opacity based on what I input in the variables menu.

              (The reason I am doing this is I want this plot to have a nice thick line but also want the OHLC bars to be visible 'underneath' - which they currently are. It is already perfectly workable as is, but as usual I am trying to use these little projects as means to learn more about Ninja script writing, and presumably others who visit the thread will also learn if and when we figure it out or indeed later determine that opacity and plots do not get on well with each other.

              The only way I can change the opacity right now is to:

              1. Change it in the Variables Section.
              2. Remove the indicator from the chart.
              3. Reload the indicator.
              4. It works. Changing opacity in the panel dialog window does nothing even though such changes print out. The first print is always the one in the Variables menu and I suspect that is the one used throughout no matter what the other opacities say.
              Last edited by cclsys; 08-17-2009, 07:51 PM.

              Comment


                #8
                Hi cclsys,

                The xml changes attribute is not related directly to your current problem. It prevents you from writing corrupted informations into the xml file when saving the workspace containing this indicator.

                Back to your problem. I tested this issue with Ninja's SampleMultiColorPlot. I can confirm your observation, it is not possible to change the plot-opacity with an own property grid entry. That means the following: When the plots are initialized the first time, they read the initial settings and are linked to an own (internal) property-system which is displayed as "Plots" in the property grid. Whenever you modify your own opacity in the property grid, the plots survive the chart reset and reject any further (outside) modifications. Or with other words: They are initialized one time only throughout the lifetime of the chart.

                You only can modify the plots with the "Plots"-section of the property grid but not by c# code. Have a look at the little picture you provided with your first post. The color depicted consists of 4 numbers. The first number is the opacity value which can be modified to your desire. It is not as nice as to have an own opacity entry, but it is a viable solution (I guess).

                Regards
                Ralph

                Comment


                  #9
                  Aha! I should have been able to find out what that first number was but was too dumb to even think. I just saw the list of numbers and moved on without investigating. I shall try getting them back into the panel and then playing from there. if it works that way, fine. Thxs again.

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    cclsys, not fully following you - with Color.FromArgb you just create a custom color...different chart paint order options (Z Order) will be supported with NinjaTrader 7 - http://www.ninjatrader.com/webnew/NT7/NinjaTrader7.html
                    Bertrand: the reason I used Color.FromArgb is because it is the only way I know to play with opacity. Is it possible to adjust opacity using the normal Color = Color.Red? If so, could you please show how to write that out?

                    Right now and with Ralph's help I just learned how to change the opacity from the Argb drop-down menus in the Indicator Dialog windows. Fine.

                    It is still strange, though. You cannot change the default colors in the Variable colors lower down in the panel. They have no effect. So the only way to change them is either by knowing the argb numbers, or opening up the code, changing the colors in there, unloading the instrument, reloading the instrument, and then you have it and from there can adjust opacity.

                    It is all fine for my purposes at this point, but I would still like to know/learn if it is possible to control the opacity of a Line Plot and have it easily configurable in the Indicator Dialog window and not have two conflicting sets of menus as shown in my first pic on the thread.

                    Comment


                      #11
                      One more comment on the 4-number color-description. It is used only in case, the color behind is unknown. For example, if you choose to use yellow, the string "Yellow" is displayed. Then you need to find out first, what the number reperesentation of yellow is before you can apply an opacity. But if you use an opacity value less than 255 as standard initialisation (as you tried to do), then you will always get a 4-number description. For example, if you combine yellow with opacity 254, you get 254; 255; 255; 0.

                      Regards
                      Ralph

                      Comment


                        #12
                        Originally posted by Ralph View Post
                        One more comment on the 4-number color-description. It is used only in case, the color behind is unknown. For example, if you choose to use yellow, the string "Yellow" is displayed. Then you need to find out first, what the number reperesentation of yellow is before you can apply an opacity. But if you use an opacity value less than 255 as standard initialisation (as you tried to do), then you will always get a 4-number description. For example, if you combine yellow with opacity 254, you get 254; 255; 255; 0.

                        Regards
                        Ralph
                        Ralph thanks for the tip/explanation. Not sure quite what you mean, but I'll play with initial code opacity values to see what happens. What I have now is that I can change the opacity value in the menu panel one plot at a time. I got it the way I want it for my purposes but if anyone else wanted to use an indicator like this pre-written, it would not be an ideal situation since you really have to adjust things in the coding, the menu panel is not enough. But again, I'll play a little more and maybe something will come through that makes it easier.

                        PS. Just realised I never sent in pic. So here's a pic of what I was working on, basically a thick line (based LinReg) that is visually prominent but which does not obscure the OHLC bars. No big deal, but sort of handy.
                        Attached Files
                        Last edited by cclsys; 08-20-2009, 11:34 AM.

                        Comment


                          #13
                          cclsys, Give my a second try to explain . On the picture of your first post you display the color SteelBlue with an opacity of 125. The result in the color field is: 125, 70, 130, 180. Now you can modify the opacity easily by modifying 125 to something different. But now recode your indicator with an opacity value of 255. The resulting color display now would be "SteelBlue". And now try to modiy the opacity of this color field if you don't know the numerical representation of SteelBlue.

                          Btw, nice picture of your indicator. I think it is a great idea to use opacity if you are using lines quite heavily on your chart, it keeps readability.

                          Regards
                          Ralph

                          Comment


                            #14
                            Thanks, Ralph. I've kicked it around and what I get with 255 is no number for opacity, then three numbers. If I change it back to 125, then I get 125 followed by the three numbers.

                            If I re-enable the Color Up, Down, Side and Opacity into the Panel, changing them does nothing.

                            So in the first case I am not getting 'Steel Blue' just the three numbers. So in order to change colors (which I personally don't need to do that much once they are written in since, like most people, I have my own preferred color scheme), I have to change the color in the code.

                            Now maybe because I have Colorup, down,side variables it is messing things up. I didn't think of removing them altogether. I will play around with this some more for learning purposes though. And thanks again.

                            Comment


                              #15
                              Ralph: just in case you get interested (!), I attach code so you can see what is there and maybe how to get it so both opacity and colors can be changed in the menus by the user.

                              In this version I have:

                              Add(new Plot(new Pen(Color.FromArgb(opacityValue, Color.Gold),7), PlotStyle.Line, "Rising"));
                              Add(new Plot(new Pen(Color.FromArgb(opacityValue, Color.RoyalBlue),7), PlotStyle.Line, "Falling"));
                              Add(new Plot(new Pen(Color.FromArgb(opacityValue, Color.Lime),7), PlotStyle.Line, "Neutral"));

                              this was after some playing around following your suggestion/explanation above. Before I had - using the public variables:

                              Add(new Plot(new Pen(Color.FromArgb(opacityValue, colorup),7), PlotStyle.Line, "Rising"));
                              Add(new Plot(new Pen(Color.FromArgb(opacityValue, colordown),7), PlotStyle.Line, "Falling"));
                              Add(new Plot(new Pen(Color.FromArgb(opacityValue, colorside),7), PlotStyle.Line, "Neutral"));

                              As far as I can tell, it makes no difference. I also tried changing the colorup,down,side & opacity value to Browsable = true in the Properties section, but - apart from getting them displayed - it also made no difference. Changing the opacity to 255 just meant the opacity number was not in the drop-down box, although you can still type in a different number, i.e. 125, and it works fine. But to change the colors - thus far at least - the only way to do it is in the code and reload the instrument.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              31 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post tkaboris  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,282 views
                              0 likes
                              Last Post Leafcutter  
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Working...
                              X