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

Bollinger Band Opacity

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

    Bollinger Band Opacity

    How would I add opacity to bollinger band color scheme?

    #2
    Hello,
    Thanks for your post.

    To accomplish this with the Bollinger Bands indicator it may be easiest to right click inside the script of the BB indicator and click "Save As.." This will allow to you to build on top of the existing indicator and make the changes that you would like.

    In your new script you would need to set your brush up as you normally would and then assign that brush to your plots. In the case of the Bollinger Bands indicator, you would need to set your custom brush to all three plots.

    To set opacity on a brush, you will need to make a new brush, and set the color and opacity you want using the Color.FromArgb() method. The following link is publicly available and goes to the MSDN page for that method.

    MSDN- Color.FromArgb()
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    As an example, the code snippet below would set each of the plots that I am adding to my indicator with a custom brush called "myBrush".

    Code:
    protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				OpacityValue					= 100;
    			
    				AddPlot(Brushes.Goldenrod, "myFirstPlot");
    				AddPlot(Brushes.Goldenrod, "mySecondPlot");
    			}	
    		}
    
    protected override void OnBarUpdate()
    		{
    					
    			if (CurrentBar < 1) return;
    			
    			Brush myBrush = new SolidColorBrush(Color.FromArgb((byte)OpacityValue, 56, 120, 153));
    			myBrush.Freeze();
    			PlotBrushes[0][0] = myBrush;
    			PlotBrushes[1][0] = myBrush;
    			
    		}
    If you would like to make opacity a configurable property inside this indicators settings, then you would also need to make sure you add a bit of code similar to the following inside your scripts Property region.

    Code:
    		[NinjaScriptProperty]
    		[Range(0, int.MaxValue)]
    		[Display(Name="OpacityValue", Description="Opacity value from 0 to 255", Order=1, GroupName="Parameters")]
    		public int OpacityValue
    		{ get; set; }
    I am including a link to our help guide documentation for working with custom brushes as well as the PlotBrushes array.

    Working with Brushes
    https://ninjatrader.com/support/help...th_brushes.htm

    PlotBrushes
    https://ninjatrader.com/support/help...lotbrushes.htm

    Please let me know if you have any further questions.
    Last edited by NinjaTrader_JoshG; 01-17-2018, 03:43 PM.
    Josh G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    6 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    9 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    20 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X