Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to shade default brush background
Collapse
X
-
No conditions are working fine. I need to know how to apply the custom brush color.
I tride below as well. But it gives correct area to color but not transparent, you need to provide clear guidance upto applying.Code:if (Close[0] >= Upper[0]) { BackBrushAll = brushCopy; //Ihow to apply custom brush coloer to "BackBrushAll"? }
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; }Last edited by Marble; 08-30-2023, 11:02 AM.
Comment
-
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 ColorHighTemp = colorHigh.Clone();
ColorHighTemp.Opacity = opacity/100; //50% is converted to .5
colorHigh = ColorHighTemp;
colorHigh.Freeze();
Brush ColorLowTemp = colorLow.Clone();
ColorLowTemp.Opacity = opacity/100; //50% is converted to .5
colorLow = ColorLowTemp;
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.
- Likes 1
Comment
-
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
-
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.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment