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

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.
    I am trying to Compare 2 Brushes as you can see in the Picture. I have no Idea why its failing...


    An example,


    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:


        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:



                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


                          #13
                          Hello,

                          how to undo PlotBrushes[1][0] = Brushes.Transparent ?
                          I tried to adapt what you did here to my case but it isn't working.

                          Greetings

                          Comment


                            #14
                            Hello seykool,

                            You should be able to set it to null to remove the brush.

                            PlotBrushes[1][0] = null;
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              That easy. Awesome.
                              Thank you Jesse!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              6 responses
                              32 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by frankthearm, Today, 09:08 AM
                              10 responses
                              36 views
                              0 likes
                              Last Post frankthearm  
                              Started by mmenigma, Today, 02:22 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by NRITV, Today, 01:15 PM
                              2 responses
                              10 views
                              0 likes
                              Last Post NRITV
                              by NRITV
                               
                              Working...
                              X