Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to shade default brush background

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

    #16
    Hello Marble,

    Your conditions are not checking for crossing which is why its true a lot. If you want to detect crossings you need to use the appropriate conditions for that. You can see examples in the help guide.


    Comment


      #17
      why is your given code is shading where all unnecessary areas.

      Comment


        #18
        Hello Marble,

        The code i provided is how to use a brush with an opacity. The reason its shading a lot is because of your conditions. If you want it to shade less frequently you need to change your conditions so that they are not true so often.

        Comment


          #19
          then why is coloring for attached is working? Can't the opacity code change the color of brush used for my code?
          I dont need to cross over bollinger band as long as last close price is upper/below.

          Comment


            #20
            Hello Marble,

            The code i provided is only how to use a brush with an opacity and that is all. That would have no effect on the overall conditions in your script. If your conditions are not working as you expect you would need to debug the conditions.

            Comment


              #21
              No conditions are working fine. I need to know how to apply the custom brush color.
              Code:
              if (Close[0] >= Upper[0])
              {
              BackBrushAll = brushCopy;  //Ihow to apply custom brush coloer to "BackBrushAll"?
              }​
              I tride below as well. But it gives correct area to color but not transparent, you need to provide clear guidance upto applying.
              Code:
              // Set 1
              if (Close[0] >= Upper[0])
              {
              double opacity = 50;
              Brush brushCopy = Brushes.Maroon.Clone();
              brushCopy.Opacity = opacity/100;
              brushCopy.Freeze();
              BackBrushAll = brushCopy;
              //BackBrushAll = brushCopy;
              }​
              Click image for larger version

Name:	image.png
Views:	190
Size:	20.8 KB
ID:	1266801
              Last edited by Marble; 08-30-2023, 11:02 AM.

              Comment


                #22
                Try putting your brush and opacity code in State.DataLoaded, not in OnBarUpdate().
                eDanny
                NinjaTrader Ecosystem Vendor - Integrity Traders

                Comment


                  #23
                  Returns error the brushCopy does not exist in the context.

                  Comment


                    #24
                    Marble, you can't just plop code in without some modifications. How about this:

                    public class Bollinger2 : Indicator
                    {
                    private SMA sma;
                    private StdDev stdDev;

                    private Brush colorHigh = Brushes.Red; // <=== for demonstration, this is like NT7
                    private Brush colorLow = Brushes.Blue;
                    // <=== Maybe move to State.SetDefaults for NT8
                    private double opacity = 50; // <=== ​Make sure to also set up Properties for these settings

                    protected override void OnStateChange()
                    {
                    if (State == State.SetDefaults)
                    {
                    Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionBollinger;
                    Name = "Bollinger2";
                    IsOverlay = true;
                    IsSuspendedWhileInactive = true;
                    NumStdDev = 2;
                    Period = 20;

                    AddPlot(Brushes.MediumSlateBlue, NinjaTrader.Custom.Resource.BollingerUpperBand);
                    AddPlot(Brushes.MediumSlateBlue, NinjaTrader.Custom.Resource.BollingerMiddleBand);
                    AddPlot(Brushes.MediumSlateBlue, NinjaTrader.Custom.Resource.BollingerLowerBand);
                    }
                    else if (State == State.DataLoaded)
                    {
                    sma = SMA(Period);
                    stdDev = StdDev(Period);

                    Brush ColorHigh​Temp = colorHigh​.Clone();
                    ColorHigh​Temp​.Opacity = opacity/100; //50% is converted to .5
                    colorHigh​ = ColorHigh​Temp​;
                    colorHigh​.Freeze();​

                    Brush ColorLow​Temp = colorLow​.Clone();
                    ColorLow​Temp​​.Opacity = opacity/100; //50% is converted to .5
                    colorLow​ = ColorLow​Temp​​;
                    colorLow​.Freeze();​​

                    }
                    }

                    protected override void OnBarUpdate()
                    {
                    double sma0 = sma[0];
                    double stdDev0 = stdDev[0];

                    Upper[0] = sma0 + NumStdDev * stdDev0;
                    Middle[0] = sma0;
                    Lower[0] = sma0 - NumStdDev * stdDev0;

                    // Set 1
                    if (Close[0] >= Upper[0])
                    {
                    BackBrushAll = colorHigh​;
                    }

                    // Set 2
                    if (Close[0] <= Lower[0])
                    {
                    BackBrushAll = colorLow​;
                    }

                    }​
                    Last edited by eDanny; 08-31-2023, 10:57 AM.
                    eDanny
                    NinjaTrader Ecosystem Vendor - Integrity Traders

                    Comment


                      #25
                      Hello dDanny

                      Thank you VERY much for the response. The post has been so helpful.
                      I have managed to create transparent back ground with shared code!!

                      Just for my learning, why below code suggested to move under State,SetDefaults for NT8?
                      (under final code, the code worked fine where stated in yours)

                      private Brush colorHigh = Brushes.Red; // <=== for demonstration, this is like NT7
                      private Brush colorLow = Brushes.Blue;​ // <=== Maybe move to State.SetDefaults for NT8

                      Marble

                      Comment


                        #26
                        I was just mentioning that this was the NT7 style of coding. If you wanted to change to NT8 style you could move to State.SetDefaults. That's all I was saying, in case it was confusing.

                        For instance, NT7 style:
                        In variables section:
                        private double opacity = 50;

                        In Properties:
                        [NinjaScriptProperty]
                        [Display(Name = "Opacity of background", Description = "Sets the opacity percentage for the background brushed 0 - 100%.", GroupName = "Background coloring", Order = 1)]
                        public double Opacity​
                        {
                        get { return opacity​; }
                        set { opacity​ = value; }
                        }​


                        For instance, NT8 style:
                        In State.SetDefaults:
                        opacity = 50;

                        In Properties:
                        [NinjaScriptProperty]
                        [Display(Name = "Opacity of background", Description = "Sets the opacity percentage for the background brushed 0 - 100%.", GroupName = "Background coloring", Order = 1)]
                        public double opacity​
                        { get; set; }
                        Last edited by eDanny; 08-31-2023, 11:09 AM.
                        eDanny
                        NinjaTrader Ecosystem Vendor - Integrity Traders

                        Comment


                          #27
                          Hi eDanny,

                          Thank you very much for detailed explanation. Understood. I have learned so much from your guidance.
                          The indicator with your coding is working great.Very appreciated.

                          Marble
                          Last edited by Marble; 09-03-2023, 05:51 PM.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          646 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          367 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          107 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          569 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          573 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X