[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"Better" Bollinger Band Indicator



PureBytes Links

Trading Reference Links

I realize it's very unlikely that I'm the first to
think of this, but I came up with a twist on Bollinger
Bands while messing around with Stridsman's Meander
indicator.

I thought... Why not calculate the StdDev using the
Open, High, Low, & Close rather than just the Close?
This led me to the 2000i function & indicator code
posted below.

I'm posting code because:

1) I put this together quickly, & I'm hoping one of
the sharper minds here can verify the accuracy of my
calculation.

2) I'd like to be able to change the lookback length
of the indicator, but I'm having trouble with the
array in the function. It wont let me pass it an input
variable as the array length (it's been awhile since I
coded array's). Right now it's hard set at 8 bars of
lookback. The array size would have to be Length * 4
for it to be variable. Any ideas from the advanced
coders?

3) Any thought's on whether or not this is actually
"better" than the original are welcome.

Thanks

Lance


{
_BetterBollinger Function
This is a synthesis of the Thomas Stridsman Meander
indicator and the Bollinger Bands indicator.
It uses all of the bars price points to calculate the
standard deviation, rather than just the close.
Lance D. Fisher 12/8/2004
}

Input: StDevs(NumericSimple);

Vars: SumVS(0) ,   StdVS(0), SetArr(0),
      SumArr(0), DiffArr(0),  Avg(0);

{First define the array}

Array: VS[32](0);

{Then use a loop function to fill it with the square
of the different price changes}

Avg = Average(AvgPrice, 8);

For SetArr = 0 To 7 Begin

  VS[SetArr * 4 + 0] = (O[SetArr] - Avg[SetArr + 1]) *
(O[SetArr] - Avg[SetArr + 1]);

  VS[SetArr * 4 + 1] = (H[SetArr] - Avg[SetArr + 1]) *
(H[SetArr] - Avg[SetArr + 1]);

  VS[SetArr * 4 + 2] = (L[SetArr] - Avg[SetArr + 1]) *
(L[SetArr] - Avg[SetArr + 1]);

  VS[SetArr * 4 + 3] = (C[SetArr] - Avg[SetArr + 1]) *
(C[SetArr] - Avg[SetArr + 1]);

End;

{Sum the array elements, to get the sum of the
squares}

For SumArr = 0 To 31 Begin

  If SumArr = 0 Then

  SumVS = 0;

  SumVS = SumVS + VS[SumArr];

End;

{Standard deviation = square root of the sum of the
squares, (or something like that)}

StdVS = SquareRoot(SumVS / 32);

{Finally, we multiply the standard deviation by the #
Std Deviations wanted, and add it to the moving
average}

_BetterBollinger = Average(AvgPrice, 8) + (StDevs *
StdVS);



{
_BetterBollinger Indicator
This is a synthesis of the Thomas Stridsman Meander
indicator and the Bollinger Bands indicator.
It uses all of the bars price points to calculate the
standard deviation, rather than just the close.
Lance D. Fisher 12/8/2004
}

Input: 	StdDevUp(2), StdDevDn(-2), Displace(0);
Variables: BBTop(0), BBBot(0), Mid(0);

BBTop = _BetterBollinger(StdDevUp);
BBBot = _BetterBollinger(StdDevDn);
Mid = Average(AvgPrice, 8);

If Displace >= 0 OR CurrentBar > AbsValue(Displace)
Then Begin
	Plot1[Displace](BBTop, "BollTop");
	Plot2[Displace](BBBot, "BollBot");
    Plot3[Displace](Mid, "Avg");
End;


		
__________________________________