Metastock formula- a bug in the soup

biggles

Active Member
#1
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 }

AlertlColor( Blue ); { Color for BBS_Ind below alert line }





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

ATR(0), { Average True Range }

SDev(0), { Standard Deviation }

BBS_Ind(0), { Bollinger Band Squeeze Indicator }

alertTextID(-1),

Denom(0),

LHMult(0);







if ( barnumber=1 ) then

Begin

If minmove <> 0 then

LHMult = pricescale/minmove;

end;



if barnumber = 1 and alertTextID = -1 then

alertTextID = Text_New(date,time,0,"dummy");



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

ATR = AvgTrueRange(Length);

SDev = StandardDev(Price, Length, 1);



Denom = (nK*ATR);

If Denom <> 0 then

BBS_Ind = (nBB * SDev) /Denom;



If BBS_Ind < Alertline then

SetPlotColor(1, NormalColor)

else

SetPlotColor(1, AlertlColor);



{-- 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[1] then

color = green

else

color = darkgreen;



if value2 < 0 then

if value2 < value2[1] then color = red

else

color = darkred;



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

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



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

if BBS_Ind crosses below AlertLine

and Text_GetTime(alertTextID) <> time then

begin

text_setLocation(alertTextID, date, time, 0);

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

end;



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

if BBS_Ind crosses above AlertLine

and Text_GetTime(alertTextID) <> time then

begin

text_setLocation(alertTextID, date, time, 0);

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

end;



if BBS_Ind crosses below AlertLine then

SetPlotColor(1, Green)
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?