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(2.5, 25).Upper, Bollinger(2, 25).Upper, null, Brushes.DarkSlateGray, 50);
// 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(2, 25).Lower, Bollinger(2.5, 25).Lower, null, Brushes.DarkSlateGray, 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 red.
if (Bollinger(2, 25).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(2.5, 25).Upper, Bollinger(2, 25).Upper, null, Brushes.Red, 100);
}
// If the price closes below the lower bollinger band, color the price region below the bollinger band red.
else if (Bollinger(2, 25).Lower[0] > Close[0])
{
Draw.Region(this,"Lower Bollinger Broken" + CurrentBar, 1, 0, Bollinger(2.0, 25).Lower, Bollinger(2.5, 25).Lower, null, Brushes.Red, 100);
}
}
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
public int Period
{ get; set; }
[Range(0, double.MaxValue), NinjaScriptProperty]
[Display(Name = "NumStdDev", GroupName = "NinjaScriptParameters", Order = 1)]
public double NumStdDev
{ get; set; }
}
}
Comment