Sunday, July 19, 2015

Bollinger Band Breakout on Squeeze

Length = 14;
Price = EMA(Close, Length);



// Keltner
kLength = Length;
kN = 1.5;
kATR = ATR(kLength);
kUpper = Price + kN * kATR;
kLower = Price - kN * kATR;






GfxSetOverlayMode(1);
GfxSetTextAlign( 1 );// center alignment
GfxSetTextColor( colorRed ) ;
GfxSetBkMode(0); // transparent
GfxSelectFont("From Cartoon Blocks", Status("pxheight")/12 );
GfxTextOut( "stockmarketq.blogspot.in", Status("pxwidth")/2, Status("pxheight")/3 );
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

// Bollinger
bbLength = Length;
bbN = 2;
bbStDevValues = StDev(Close, bbLength);
bbUpper = Price + bbN * bbStDevValues;
bbLower = Price - bbN * bbStDevValues;

IsBBSqueeze = bbUpper <= kUpper AND bbLower >= kLower;

Proportion = (kUpper - kLower) / (bbUpper - bbLower);
BBBreakout = Cross(1,Proportion);
Periods = Param("BBPeriods", 14, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
bbtop=BBandTop( C, Periods, Width );
bbbot=BBandBot( C, Periods, Width );
Plot(bbtop, "", Color, Style );
Plot(bbbot , "", Color, Style );

sqeezcolor=ColorRGB(194,220,218);

PlotOHLC( bbtop,bbtop, bbbot,bbbot, "",IIf(IsBBSqueeze,colorYellow,colorLightGrey), styleCloud|styleNoRescale,  Null, Null, Null, -1 );
Plot(Close,"Close",IIf(C>=O,colorBrightGreen,colorRed),styleCandle);

Filter = BBBreakout AND V>50000 AND C>30;

AddColumn(BBBreakout, "BB Breakout", 1, colorWhite, IIf(BBBreakout==1, colorBlue, colorWhite));
//set default sorting to Date/time in descending order in results window
SetSortColumns(-2);


No comments:

Post a Comment