What do I need to add in the code so the diamonds are drawn on all previous events? In this case, bar close outside Bollinger Band.
public class SampleDrawRegion : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "SampleDrawRegion";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = false;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
Period = 14;
NumStdDev = 2;
}
}
protected override void OnBarUpdate()
{
// With the DrawRegion() method you can fill the space inbetween two DataSeries objects very easily.
// This region fills in the space between the Upper Bollinger Band and the Middle Bollinger Band. The region extends from the first bar of the chart
// till the last bar of the chart. It has a border color of black and is filled with blue on an opacity setting of 2. Opacity setting ranges from 0-10.
// 0 being transparent and 10 being completely colored.
Draw.Region(this, "Bollinger Upper Region", CurrentBar, 0, Bollinger(NumStdDev, Period).Upper, Bollinger(NumStdDev, Period).Middle, Brushes.Black, Brushes.Blue, 20);
// This region fills the space between the Lower Bollinger Band and the Middle Bollinger Band. It has the same attributes as the previous region, except
// the blue fill color is darker in this one. If you wish to create a region without a border you can use this color: Color.Transparent
Draw.Region(this,"Bollinger Lower Region", CurrentBar, 0, Bollinger(NumStdDev, Period).Lower, Bollinger(NumStdDev, Period).Middle, Brushes.Black, Brushes.Blue, 50);
// Besides filling inbetween two DataSeries objects we can also fill between a double value and a DataSeries.
// This is demonstrated in the following code segment.
// If the price closes above the upper bollinger band, color the price region above the bollinger band gold.
if (Bollinger(NumStdDev, Period).Upper[0] < Close[0])
{
// In our string tag we use "+ CurrentBar" to ensure unique tag names for all our regions. If we did not have unique names each call
// upon the tag would modify the existing DrawRegion() instead of coloring a new one.
Draw.Region(this,"Upper Bollinger Broken" + CurrentBar, 1, 0, Bollinger(NumStdDev, Period).Upper, High[0], Brushes.Black, 100);
Draw.Diamond(this, "Diamond High", true, 0, High[0] + TickSize, Brushes.Green);
}
// If the price closes below the lower bollinger band, color the price region below the bollinger band gold.
else if (Bollinger(NumStdDev, Period).Lower[0] > Close[0])
{
Draw.Region(this,"Lower Bollinger Broken" + CurrentBar, 1, 0, Bollinger(NumStdDev, Period).Lower, Low[0], Brushes.Black,100);
Draw.Diamond(this, "Diamond Low", true, 0, Low[0] - TickSize, Brushes.Red);
}
}
Comment