Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PlotBrushes

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

    PlotBrushes

    I am playing around with Plots using the example under PlotBrushes. I have basically made 2 EMA ribbons that will change color based on if it's rising or falling using this code within OnBarUpdate():

    for (int i = 0; i < PlotBrushes.Count(); i++)
    {
    PlotBrushes[i][0] = (i < numberOfEMAPerRibbon) ? (IsRising(Values[i]) ? EMA1RibbonUpColor : EMA1RibbonDownColor) : (IsRising(Values[i]) ? EMA2RibbonUpColor : EMA2RibbonDownColor);
    }​

    This gives the ribbons one of two colors depending on if it's rising or falling.
    I wanted to add buttons to change the plotBrushes color to transparent, or if it is already transparent, change it back.

    Can I use PlotBrushes[0][0] = Brushes.Transparent in this case? I tried and it's not working?
    I have succeeded in hiding EMAs with a button before with Plots[0].Brush = Brushes.Transparent; but that is not working in this case either.

    Any idea if I'm doing something wrong, or I'm just going about this the wrong way?

    #2
    Hello rockmanx00,

    You can use PlotBrushes for that use, you would have to loop over the bars and supply an index to PlotBrushes[0][index] to set each bars color to transparent or some other color.

    Comment


      #3
      Ok. I tried that but couldn't get it to work. Then again I did it the other way around with PlotBrushes[index][0] so I'll try again.

      Comment


        #4
        Hello rockmanx00,

        That is why I had specified Index in that location, the first brackets are the plot index. You need to use 0 if its the first plot.

        Comment


          #5
          and the [index] would be the barsago portion of it? So I have to change the color for every section of the plotbrush[0]?

          Comment


            #6
            Hello rockmanx00,

            Right, its [plotindex][barsago]

            Comment


              #7
              I'm getting an Unhandled exception error. Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index.

              I didn't even loop. I just tested with PlotBrushes[0][1]= Brushes.Transparent;
              The only number that doesn't give an error is PlotBrushes[0][0]= Brushes.Transparent; but it doesn't seem to make the plot transparent at all.

              Comment


                #8
                i have some custom indicators for those willing

                Comment


                  #9
                  Hello rockmanx00,

                  You are trying to se the 1 bars ago value on the primary plot, if you did that on bar 0 that is not valid. You would have to have a condition like this before that code

                  if(CurrentBar < 1) return;

                  Comment


                    #10
                    Huh....I hadn't even noticed I didn't have that on. I normally do on most of my code. I will try this again and figure out the logic for looping. If I'm using a button to activate the loop to make all the already loaded plots transparent, does that matter? It doesn't start as if it's loading the bars from the beginning right? I would think that since the bars are all loaded, you could do something like PlotBrushes[0][5] = Brushes.Transparent to change the section 5 bars ago to transparent without having an out of bounds array.

                    Comment


                      #11
                      Hello rockmanx00,

                      If you are trying to use a button to control plots I would suggest stating from a known working example, you can see the following which hides plots using a button. https://ninjatraderecosystem.com/use...ect-invisible/

                      Comment


                        #12
                        I do have a working example, from which I copied the button logic. The only difference in my case is that the original buttons I use to hide the EMAs simply uses Plots[0].Brush = Brushes.Transparent to change it. That works for me with that simple EMA. I tried that with this case but it didn't work. I'm assuming it's different since I'm using PlotBrushes [0][0] to create the plot colors in the first place.

                        I will look at the example you provided again to see if I can gain any other insight from it. Thank you.
                        Last edited by rockmanx00; 02-28-2025, 09:42 AM.

                        Comment


                          #13
                          Hello rockmanx00,

                          For the purpose of hiding plots I would suggest using the indicators IsVisible property like the sample I linked, that is a lot less resource use and works over large bar sets where PlotBrushes would require looping.

                          Comment


                            #14
                            Ok. Good to know. I will check that out. Thank you.

                            Comment


                              #15
                              Looking at the sample, how exactly would I apply that to Plots or PlotBrushes? The example shows how to do it with draw objects, but .IsVisible does not seem to apply to Plots or PlotBrushes directly.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              558 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              324 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              545 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              547 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X