#### Topic: How to add shift to bands indicators

Moving average and Donch channel have shift function by bars
but when come to band like bollingerbands it will not work

i modified the BB indicator with shift function it compiled fine  but the logic changed because of StDev not shifted ''i think''

How to fix this obstacle

Regards

#### Re: How to add shift to bands indicators

Ahmed, the best way I think would be to look at other indicators with vertical shift, like Recent Swing High Low. Look how it's done, and implement it similarly (new for loop after the main one, then add the shift to upper and lower band).

#### Re: How to add shift to bands indicators

``````IndParam.NumParam.Caption = "Shift";
IndParam.NumParam.Value = 0;
IndParam.NumParam.Min = 0;
IndParam.NumParam.Max = 200;
IndParam.NumParam.Enabled = true;
IndParam.NumParam.ToolTip = "The number of bars to shift with.";

// The CheckBox parameters
IndParam.CheckParam.Caption = "Use previous bar value";
IndParam.CheckParam.Enabled = true;
IndParam.CheckParam.ToolTip = "Use the indicator value from the previous bar.";``````
``````var iShift = (int)IndParam.NumParam.Value;
int prvs = IndParam.CheckParam.Checked ? 1 : 0;``````
``double[] adMA = MovingAverage(nMA, iShift, maMethod, adPrice);``
``````int firstBar = nMA + iShift + prvs + 2;

for (int bar = nMA; bar < Bars - iShift; bar++)
{
double sum = 0;
for (int i = 0; i < nMA; i++)
{
sum += delta*delta;
}
double stdDev = Math.Sqrt(sum/nMA);
}``````

#### Re: How to add shift to bands indicators

and this what i have done  in the previous post these changes i have done  but visually after i plot on screen there are differences !!!!

I think the problem in the StDev part but couldnot figure how tofix it .

#### Re: How to add shift to bands indicators

Oops, sorry, I misread you. You want bar shifts.

No need to shift adMa, you should shift the whole band only.

This should be what you're looking for.

``````adUpBand[bar + iShift] = adMA[bar] + mpl* stdDev;

#### Re: How to add shift to bands indicators

footon wrote:

Oops, sorry, I misread you. You want bar shifts.

No need to shift adMa, you should shift the whole band only.

This should be what you're looking for.

``````adUpBand[bar + iShift] = adMA[bar] + mpl* stdDev;
``for (int bar = firstBar; bar < Bars - iShift; bar++)``