I have wanted to change background color when closes above or below bollinger band.
Currently, the color is solid but I want to tone down the color and show as 70% transparent of default color. (if 0% transparent is solid color) (ref, image - ideal)
public class Bollinger2 : Indicator
{
private SMA sma;
private StdDev stdDev;
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);
}
}
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 = Brushes.Maroon;
}
// Set 2
if (Close[0] <= Lower[0])
{
BackBrushAll = Brushes.DarkGreen;
}
}
BackBrushAll = Brushes.Maroon;
BackBrushAll = Brushes.DarkGreen;
Marble

Comment