Thanks in advance for any help.
Here is the code:-
{
#region Variables
private double sndDev;
private int myInput0 = 1; // Default setting for MyInput0
private int tBIP; // tick bars BIP Series variable
#endregion
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "Mean"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "+2Std"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "-2Std"));
Add(PeriodType.Tick, 1); // add 1 Tick data series
Overlay = true;
// sets 1 Tick bars in Progress series
if(BarsPeriod.Id == PeriodType.Tick && BarsPeriod.BasePeriodValue == 1)
{
tBIP = 0;
}
else
tBIP = 1;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if( CurrentBars[tBIP] < sDPeriod)
return;
if( BarsInProgress == tBIP ); // always use 1 tick data for calculations
{
sndDev = StdDev( Closes[tBIP], sDPeriod )[0];
Values[0].Set( SMA( Closes[tBIP], sDPeriod )[0] );
Values[1].Set( SMA( Closes[tBIP], sDPeriod )[0] + 2*sndDev );
Values[2].Set( SMA( Closes[tBIP], sDPeriod )[0] - 2*sndDev );
}
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}
private int sDPeriod;
[Description("")]
[GridCategory("Parameters")]
public int SDPeriod
{
get { return sDPeriod; }
set { sDPeriod = Math.Max(1, value); }
}
#endregion
}

Comment