• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Checking the Color of a Plot

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

    Checking the Color of a Plot

    Hello,

    Let say I want to check if the selected color for a plot is a given color...

    Why this doesn't work
    Print(Plots[0].Brush==Brushes.Blue); ( it is always false )

    ...and instead this works fine ?
    Print(Plots[0].Brush.ToString() ==Brushes.Blue.ToString());

    Thanks !
    pmaglio
    NinjaTrader Ecosystem Vendor - The Indicator Store

    #2
    Hello Pmaglio,

    Thank you for your note.

    The two won't be equal because its doing a reference comparison and they are two different references.

    I would suggest the following link for more explanation.
    http://stackoverflow.com/questions/2...lidcolorbruhes

    An example,
    https://www.codeproject.com/Tips/510...using-IsEquals

    Please let us know if you need further assistance.
    Last edited by NinjaTrader_AlanP; 02-23-2017, 09:47 AM.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      hello,

      Why it's not possible to convert plot brushes to string.

      for example :

      Print( PlotBrushes[5][4] ) display hex brush

      But Print( PlotBrushes[5][4].ToString() ) doesn't not work.

      I need to variable with brush.

      I need to get brush of a plot on each Bar . There are 30 plots .


      thank you

      Comment


        #4
        Hello oceanis400,

        Thank you for the reply.

        It is possible to make a brush into a string, but you would need to do this in the correct way and you would need an instance to a brush. Are you currently setting a brush to the PlotBrushes collection for the bar being referenced? This is an empty collection to start with, so calling PlotBrushes[5][4].ToString() would generate the error Object reference not set to an instance of an object if no brush was set to this bar.

        I would likely suggest using the serialize functions from our working with brushes documentation:
        https://ninjatrader.com/support/help...definedbrushes

        Code:
        Print(Serialize.BrushToString(PlotBrushes[5][4]));
        If there is no brush set you would see DEFAULT, otherwise, a serialized brush would be output. You can also use .ToString() from a brush instance but if there is no brush it would produce an error:

        Code:
        Print( PlotBrushes[5][4].ToString() )
        If you are trying to get the color the user defined for the plot, that would instead be the following:

        Code:
        foreach(Plot plot in Plots)
        {
            Print(plot.Name + " " + plot.Pen.Brush.ToString());
        }
        The Plots brush that is set in the UI is a completely different brush than PlotBrushes, you can think of PlotBrushes as a secondary brush that is used for specific bars.


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

        Comment


          #5
          Hello Jesse,

          You last code is interesting.

          I know the name of each plot.

          So is it possible to have Brush at specific Bar with plot name

          for example : BrushToTest = plot[5][4]."MyName".pen.brush.ToString()

          I need to use past color of the plot.

          Color of one plot change on every Bar.


          thank you

          Comment


            #6
            Hello oceanis400,

            I wanted to clarify what you are trying to do as you are displaying conflicting syntax with what you are explaining that you want to do.

            In my prior post I noted two different items, the first was explaining the PlotBrushes and the second was explaining the overall defined plot color.

            The plot.Pen.Brush represents the entire plot, all bars of the plot and is what the user defined when they apply the script. This would not be helpful if you are trying to do something for each bar based on a condition changing the plots color.

            If you are trying to do something for each bar, I would also not likely suggest using the Brush of the plot to determine changes but I would suggest using a Series if you need to store something for each bar and later reference it. The Plots Brushes would only be relevant in this script so if there is any plan of later exposing these changes as a signal you would still need to use a Series for this purpose anyway.

            In case I have misunderstood what you are trying to do, it would be helpful If you can provide a more broad overview of the goal you are trying to achieve. So far I have understood you are trying to use the plots color from each bar in some way, based on the description it seems you are also setting the plots color in some condition in another part of the script.





            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Yes I tried to explain better.

              In this example you have 8 plots horizontally. (some plot are black)
              I try to know which plot have color on each bar. (all color are made with Argb(255,byte,byte,byte)

              Comment


                #8
                Hello oceanis400,

                Yes, in this case, I would still suggest using Series for this purpose to mark the bar as having a signal. You could do this fairly easily using a few series and using integers to denote which signal the bar represents, this would be to support the shades of colors shown in the image.

                You can also use the PlotBrushes collection, but as noted you will see errors if there is no brush set and this is only going to work inside of this indicator if it sets the plots colors. To use this would require some error checking and is also not the direction I would suggest as you are doing string comparisons.

                To make a series which represents the plot colors, you could do something similar to the sample in the Series<T> page using integers:

                https://ninjatrader.com/support/help...us/seriest.htm

                Here is an example for one plot, assuming you have some condition to set the plots colors it would look similar to the following:

                Code:
                private Series<int> myFirstPlotSignal; 
                
                protected override void OnStateChange() 
                {
                    if (State == State.DataLoaded)
                    {
                        myFirstPlotSignal = new Series<int>(this, MaximumBarsLookBack.Infinite);
                    }
                }
                
                protected override void OnBarUpdate()
                { 
                    myFirstPlotSignals[0] = 0; // reset to 0, this is so the series has a value for each bar to check. 0 just means nothing was set for this bar
                
                    if(conditionToSetColor)
                    {
                       //logic setting plots color
                       myFirstPlotSignal[0] = 1;
                    }
                
                    if(myFirstPlotSignals[0] == 1)
                    {
                        //Color on this bar was set
                    }
                
                }

                This would make a 1 for each bar where the color has been set, the series could be made visible for other scripts to access if needed and you can also use the Series methods and BarsAgo system to do other logic related to this color.

                Here is another example showing multiple colors for the same series
                Code:
                protected override void OnBarUpdate()
                { 
                    myFirstPlotSignals[0] = 0; // reset to 0, this is so the series has a value for each bar to check. 0 just means nothing was set for this bar
                
                    if(conditionToSetColor)
                       myFirstPlotSignals[0] = 1;
                    if(somethingElse)
                       myFirstPlotSignals[0] = 2;
                
                
                   if(myFirstPlotSignals[0] == 1)
                   {
                       //Color on this bar was set
                   }
                   else if(myFirstPlotSignals[0] == 2)
                   {
                       //A different color was set on this bar
                    }
                
                    if(myFirstPlotSignals[4] == 2) // checking the color 4 bars ago
                    {
                
                    }
                }
                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  hello Jesse,

                  Is it possible to get Color or Brush of ChartObject in a Chart.


                  foreach (ChartObject co in ChartControl.ChartObjects)
                  {
                  // do your stuff here
                  Print(co.Y.ToString());
                  }

                  thank you

                  Comment


                    #10
                    Hello oceanis400,

                    Thank you for the question.

                    What kind of chart object? The answer is likely no, for example, a Plot you can likely get the initial default value which is set for the plot, but if it toggles the plots color later that would not be detectable. Can you detail further what you are trying to do?


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

                    Comment


                      #11
                      I try to detect color of little rectangle "Cyan color" Bottom of Bar , I can read property with right click on rectangle.

                      See picture.

                      thank you

                      Attached Files

                      Comment


                        #12
                        Hello oceanis400,

                        Thank you for your reply.
                        For a drawing object, you may be able to read this.

                        You would need to cast your found chart object to a rectangle so you can access the rectangle specific brushes.

                        Code:
                        if(co is Rectangle)
                        {
                           Rectangle r = co as Rectangle;  
                           // check brushes of the R object
                           Print(r.AreaBrush.ToString());
                        }
                        You will need to check this in your use case to see if the default brush is found or the currently draw brush is found.

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

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by deblanka, Today, 08:56 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post deblanka  
                        Started by Boonfly8, Yesterday, 12:30 PM
                        7 responses
                        18 views
                        0 likes
                        Last Post sledge
                        by sledge
                         
                        Started by Sohal, Today, 05:02 AM
                        1 response
                        8 views
                        0 likes
                        Last Post Sohal
                        by Sohal
                         
                        Started by danitralla, Today, 03:33 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post danitralla  
                        Started by yeshujbp, Today, 12:37 AM
                        0 responses
                        14 views
                        0 likes
                        Last Post yeshujbp  
                        Working...
                        X