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

Post's attachments

BollingerBands1.cs 26.3 kb, 4 downloads since 2013-12-07 

You don't have the permssions to download the attachments of this post.

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[2].Caption = "Shift";
            IndParam.NumParam[2].Value = 0;
            IndParam.NumParam[2].Min = 0;
            IndParam.NumParam[2].Max = 200;
            IndParam.NumParam[2].Enabled = true;
            IndParam.NumParam[2].ToolTip = "The number of bars to shift with.";

            // The CheckBox parameters
            IndParam.CheckParam[0].Caption = "Use previous bar value";
            IndParam.CheckParam[0].Enabled = true;
            IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
var iShift = (int)IndParam.NumParam[2].Value;
            int prvs = IndParam.CheckParam[0].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++)
                {
                    double delta = (adPrice[bar - i] - adMA[bar]);
                    sum += delta*delta;
                }
                double stdDev = Math.Sqrt(sum/nMA);
                adUpBand[bar + iShift] = adMA[bar + iShift] + mpl* stdDev;
                adDnBand[bar + iShift] = adMA[bar + iShift] - mpl * stdDev;
            }

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 .

Post's attachments

bo plus Bo shift.gif
bo plus Bo shift.gif 13.34 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

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;
adDnBand[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;
adDnBand[bar + iShift] = adMA[bar] - mpl * stdDev;

i tried it before but not working !!!

Post's attachments

bo.gif
bo.gif 11.77 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: How to add shift to bands indicators

That's weird. It can't be that it doesn't work. Hmm...

Keep my suggestion, shift only the band itself and change the starting point of the for loop like below:

for (int bar = firstBar; bar < Bars - iShift; bar++)