# Metastock formula- a bug in the soup

#### biggles

##### Active Member
Hello experts,

I have this formula for keltner and bollinger band histogram. There seems to be a bug in it. Doesn't do its thing. Can someone proficient and with time on his hands debug it for metastock 8. Thanks

Inputs: {------------------------------------------------}

Price(Close),

Length(20), { Length for Average True Range (ATR) & Std. Deviation (SD) Calcs }

nK(1.5), { Keltner Channel ATRs from Average }

nBB(2), { Bollinger Band Std. Devs. from Average }

AlertLine( 1 ), { BBS_Index level at which to issue alerts }

NormalColor( Red ), { Normal color for BBS_Ind }

Variables: {---------------------------------------------}

ATR(0), { Average True Range }

SDev(0), { Standard Deviation }

BBS_Ind(0), { Bollinger Band Squeeze Indicator }

Denom(0),

LHMult(0);

if ( barnumber=1 ) then

Begin

If minmove <> 0 then

LHMult = pricescale/minmove;

end;

if barnumber = 1 and alertTextID = -1 then

{-- Calculate BB Squeeze Indicator ----------------------}

ATR = AvgTrueRange(Length);

SDev = StandardDev(Price, Length, 1);

Denom = (nK*ATR);

If Denom <> 0 then

BBS_Ind = (nBB * SDev) /Denom;

SetPlotColor(1, NormalColor)

else

{-- Plot the Index & Alert Line -------------------------}

Plot1(0, "BBS_Ind");

{-- Plot delta of price from Donchian mid line ----------}

value2 = LinearRegValue(price-((Highest(H, Length)+Lowest(L, Length))/2

+ xAverage(c,Length))/2,Length,0);

var:color(0); color = yellow;

if value2 > 0 then

if value2 > value2 then

color = green

else

color = darkgreen;

if value2 < 0 then

if value2 < value2 then color = red

else

color = darkred;

Plot3(value2*LHMult, "NickmNxtMove", color);

{plot3(value2,"BB Squeeze",color);}

{-- Issue Alert when the Squeeze is On ------------------}

begin

Alert("Check for Squeeze Setups on " + SymbolName);

end;

{-- Issue Alert when the Squeeze Releases ---------------}

begin

Alert("Squeeze is Over on " + SymbolName);

end;

if BBS_Ind crosses below AlertLine then

SetPlotColor(1, Green)