Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

BB Squeeze TradeStation Code Port for Amibroker (AFL)
niladri
almost 4 years ago
Amibroker (AFL)

Rating:
5 / 5 (Votes 3)
Tags:
amibroker, squeeze, oscillator

BB Squeeze ( 100% conversion from Tradestation code to Amibroker)

Best Volatility breakout indicator ( either on buy or sell side , ref below video to understand the logic )

Instructions:

Insert Linked to new chart pane
Periods can be selected in Param window

Usage Demo from TradeStaion: https://www.youtube.com/watch?v=v2pbrz9K7X8 ( 20min onwards )

Squeeze play with Options Trade: https://tickertape.tdameritrade.com/tools/fearless-technician-ttm-squeeze-indicator-15072

Screenshots

Indicator / Formula

Copy & Paste Friendly

Insert Linked to new chart pane

_SECTION_BEGIN("BB Squeeze"); 
Price = Close;

Length = Param("Length",20,2,100,1); 		// { Length for Average True Range (ATR)}
Lenght1 = Param("Length1",20,2,100,1);       // {  Std. Deviation (SD) Calcs }
 
nK = Param("Channel ATRs",1.5,0.1,2,0.1); 	// { Keltner Channel ATRs from Average }
nBB = Param("BB Std Devs",2,0.1,3,0.1); 	// { Bollinger Band Std. Devs. from Average }

AlertLine = Param("AlertLine",1,0,3,1); 	        // { BBSqueezeex level at which to issue alerts }
 
NormalColor = colorRed; 				// { Normal color for BBSqueeze }
AlertlColor = colorLime; 					// { Color for BBSqueeze below alert line }
 
LHMult = Nz(PointValue);
 
//{-- Calculate BB Squeeze Indicator ----------------------}
AvgTrueRange = ATR(Length);
SDev = StDev(Price, Length);
 
Denom = nK*AvgTrueRange;
BBSqueeze = Nz((nBB * SDev) /Denom); 
 
SetPlotColor = IIf( BBSqueeze < Alertline, NormalColor, AlertlColor);

BBcrossDown = Cross(AlertLine,BBSqueeze);
BBcrossUp = Cross(BBSqueeze,AlertLine);
 
//{-- Plot the Alert Line -------------------------}
Plot(0, "", SetPlotColor, styleDots );

//{-- Plot delta of price from Donchian mid line ----------}
value2 = LinearReg( price-((HHV(H, Lenght1)+LLV(L, Lenght1))/2+ MA(C,Lenght1))/2, Lenght1);
color = IIf( value2 > 0, IIf( value2 > Ref(value2,-1), colorBlue, colorSkyblue), IIf( value2 < 0, IIf( value2 < Ref(value2,-1), colorRed, colorYellow ), colorGold ));
 
//Plot(value2*LHMult, "NickmNxtMove", color, styleHistogram );
Plot(value2,"BBSqueeze",color, styleHistogram );
 
//Sound alerts
AlertIf( BBcrossDown, "SOUND C:\\Windows\\Media\\RINGIN.WAV", "Audio alert", 2 );
AlertIf( BBcrossUp, "SOUND C:\\Windows\\Media\\RINGIN.WAV", "Audio alert", 2 );

PlotShapes( IIf( BBcrossDown, shapeHollowCircle, shapeNone ), colorYellow, layer = 0, yposition = 0, offset = 0);
PlotShapes( IIf( BBcrossUP, shapeHollowCircle, shapeNone ), colorWhite, layer = 0, yposition = 0, offset = 0);
_SECTION_END();

6 comments

1. anjan123

May I request for buy sell explorer.

2. endhuetz

NICE formula dude!
can you adding explore for buy / sell exploration please

3. hotaro3

Good Indicator

4. hotaro3

//A better code for BB Squeeze is as KP TTM Squeeze Follows

_SECTION_BEGIN(“The Squeeze”);
SetChartBkColor(ParamColor(“Panel Color”,colorLightGrey));
SetChartBkGradientFill(ParamColor(“Upper Chart”,colorLightGrey),ParamColor(“Lower Chart”,colorLightGrey));

SetChartOptions( 0, chartShowDates|chartWrapTitle );
Price = Close;
Length = Param(“ATR Length”,20,2,100,1); // { Length for Average True Range (ATR)}
Lenght1 = Param(“SD Length”,20,2,100,1); // { Std. Deviation (SD) Calcs }
nK = Param(“Channel ATRs”,1.4,0.1,2,0.1); //{ Keltner Channel ATRs from Average }
nBB = Param(“BB Std Devs”,2,0.1,3,0.1); // { Bollinger Band Std. Devs. from Average }
AlertLine = Param(“AlertLine”,1,0,3,1); //{ BBS_Index level at which to issue alerts }
NormalColor = 4; //{ Normal color for BBS_Ind }
AlertlColor = 10;// Color for BBS_Ind below alert line }
LHMult = Nz(PointValue/TickSize);
//{— Calculate BB Squeeze Indicator -—————————-}
AvgTrueRange = ATR;
SDev = StDev(Price, Length);
Denom = nK*AvgTrueRange;
BBS_Ind = Nz((nBB * SDev) /Denom);
SetPlotColor = IIf( BBS_Ind < Alertline, NormalColor, AlertlColor);
BBcrossDown = Cross(AlertLine,BBS_Ind);
BBcrossUp = Cross(BBS_Ind,AlertLine);
Plot(0, “BBS_Ind”, SetPlotColor, styleDots|styleThick | styleNoRescale |styleNoLabel );
//{— Plot delta of price from Donchian mid line -———-}
value2 = LinearReg( price-((HHVLLV)/2 MA)/2, Lenght1);
color = IIf( value2 > 0, IIf( value2 > Ref(value2,-1), colorBlue, 12), IIf( value2 < 0, IIf( value2 < Ref(value2,-1), ParamColor(“UpColor”,colorRed ), colorYellow ), colorYellow ));
myma=WMA;
//Plot(value2*LHMult, “NickmNxtMove”, color, styleBar | styleThick|styleOwnScale );
Plot(value2,“BB Squeeze”,color, styleArea | styleThick);
PlotShapes( IIf( Cross(Value2, 0), shapeHollowSmallDownTriangle+ shapePositionAbove, shapeNone ), 29,0,Offset=0 );
PlotShapes( IIf( Cross(0, Value2), shapeUpTriangle+ shapePositionAbove, shapeNone ), 32,0,Offset=0);
PlotShapes(IIf(Cross(myma,value2),shapeuparrow+ shapePositionAbove, shapeNone ), 12,0,Offset=myma);
PlotShapes(IIf(Cross(Value2 ,myma),shapedownarrow+ shapePositionAbove, shapeNone ),7 ,0,Offset=myma,-10);
//Plot(myma,"",5,styleLine|styleThick);
//{— Issue Alert when the Squeeze is On -———————-}
ALERT”;
//Write alerts to Interpretation window
//Ticker = Name();
//WriteIf(BBcrossDown,Ticker + " " + “BB Squeeze Alert” ,WriteIf(BBcrossUp,Ticker + " " + “BB Squeeze Is Over”,""));
//Write alerts to Alert Output window
//AlertIf(BBcrossDown,"",“BB Squeeze Alert”,0);
//AlertIf(BBcrossUp,"",“BB Squeeze Is Over”,0);
//Sound alerts
//AlertIf( BBcrossDown, “SOUND C:\\Windows\\Media\\RINGIN.WAV”, “Audio alert”, 2 );
//AlertIf( BBcrossUp, “SOUND C:\\Windows\\Media\\RINGIN.WAV”, “Audio alert”, 2 );
//Write text to screen
//ytext = 0.01;
/*
or(i=1;i<BarCount;i++)
{
If(BBcrossDown[i])
{

PlotText(“ON”,i,-ytext[i],colorWhite);
}

if(BBcrossUp[i])

{

PlotText(“OFF”,i,ytext[i],colorWhite);

}

}

*/

//PlotShapes(shapeUpArrow*BBcrossDown,colorWhite,0,0);
//PlotShapes(shapeDownArrow*BBcrossup,colorWhite,0,0);
_SECTION_END();

/SECTION_BEGIN(“KP Fast 2”);
//SetChartBkColor(ParamColor(“Panel Color”,colorLightGrey));
//SetChartBkGradientFill(ParamColor(“Upper Chart”,colorLightGrey),ParamColor(“Lower Chart”,colorLightGrey));
//tskp_fast2val1, tskp_fast2val2
dummy=E_TSKPFAST2(Open,High,Low,Close,Volume);
Plot(tskp_fast2val1,“Fast2_1”,ParamColor(“ColorUp”,colorBlue),styleLine|styleThick);
Plot( tskp_fast2val2,“Fast2_2”,ParamColor(“ColorDown”,colorRed),styleLine|styleThick);
PlotShapes(IIf(Cross(tskp_fast2val1,0),shapeDigit1+ shapePositionAbove, shapeNone ), 29,0,Offset=tskp_fast2val1,-12 );
PlotShapes(IIf(Cross(0,tskp_fast2val2),shapeDigit1+ shapePositionAbove, shapeNone ), 4,0,Offset=tskp
fast2val2,12 );
//Plot(0,"",ParamColor(“Zero Line”,colorGrey50),styleLine|styleNoLabel);
//Title =FullName();
_SECTION_END();
/

SECTION_BEGIN(“KP M Range”);
mp=0.5*(High + Low);
tightstop=E_TSKPTIGHTSTOP(High,Low,Close);
stopline=E
TSKPSTOPLINE;
Color=colorWhite;
for( i = 0; i < BarCount; i++ )
{
if( mp[i] > stopline[i] && mp[i] > tightstop[i] )
Color[i] = colorBlue;
else if( mp[i] < stopline[i] && mp[i] < tightstop[i])
Color[i] = colorRed;
else
Color[i] = colorWhite;
}
Plot(0,"",Color,styleOwnScale|styleArea|styleNoLabel,0, 90 );
Plot(7,"",Color,styleOwnScale|styleArea|styleNoLabel,0, 90 );
_SECTION_END();

SECTION_BEGIN(“KP TrendBias BackGround”);//Plot Tone
dummy = E_TSKPTRENDBIAS(High,Low,Close);
KPTB = tskp_sb;
KPTBSlow = tskp
tbxavg;
parmToneColorUp=ParamColor(“Tone Color Up”, colorLightBlue );
parmToneColorDn=ParamColor(“Tone Color Dn”, colorTan);
RibbonSize=Param(“Ribbon Size”,20,0.5,10,0.5);
Plot( RibbonSize,"",IIf(KPTB > KPTBSlow,parmToneColorUp,parmToneColorDn),styleOwnScale|styleArea|styleNoLabel,0,10);
_SECTION_END();

5. hotaro3

//A better code for BB Squeeze is as KP TTM Squeeze Follows

_SECTION_BEGIN(“The Squeeze”);
SetChartBkColor(ParamColor(“Panel Color”,colorLightGrey));
SetChartBkGradientFill(ParamColor(“Upper Chart”,colorLightGrey),ParamColor(“Lower Chart”,colorLightGrey));

SetChartOptions( 0, chartShowDates|chartWrapTitle );
Price = Close;
Length = Param(“ATR Length”,20,2,100,1); // { Length for Average True Range (ATR)}
Lenght1 = Param(“SD Length”,20,2,100,1); // { Std. Deviation (SD) Calcs }
nK = Param(“Channel ATRs”,1.4,0.1,2,0.1); //{ Keltner Channel ATRs from Average }
nBB = Param(“BB Std Devs”,2,0.1,3,0.1); // { Bollinger Band Std. Devs. from Average }
AlertLine = Param(“AlertLine”,1,0,3,1); //{ BBS_Index level at which to issue alerts }
NormalColor = 4; //{ Normal color for BBS_Ind }
AlertlColor = 10;// Color for BBS_Ind below alert line }
LHMult = Nz(PointValue/TickSize);
//{— Calculate BB Squeeze Indicator -—————————-}
AvgTrueRange = ATR;
SDev = StDev(Price, Length);
Denom = nK*AvgTrueRange;
BBS_Ind = Nz((nBB * SDev) /Denom);
SetPlotColor = IIf( BBS_Ind < Alertline, NormalColor, AlertlColor);
BBcrossDown = Cross(AlertLine,BBS_Ind);
BBcrossUp = Cross(BBS_Ind,AlertLine);
Plot(0, “BBS_Ind”, SetPlotColor, styleDots|styleThick | styleNoRescale |styleNoLabel );
//{— Plot delta of price from Donchian mid line -———-}
value2 = LinearReg( price-((HHVLLV)/2 MA)/2, Lenght1);
color = IIf( value2 > 0, IIf( value2 > Ref(value2,-1), colorBlue, 12), IIf( value2 < 0, IIf( value2 < Ref(value2,-1), ParamColor(“UpColor”,colorRed ), colorYellow ), colorYellow ));
myma=WMA;
//Plot(value2*LHMult, “NickmNxtMove”, color, styleBar | styleThick|styleOwnScale );
Plot(value2,“BB Squeeze”,color, styleArea | styleThick);
PlotShapes( IIf( Cross(Value2, 0), shapeHollowSmallDownTriangle+ shapePositionAbove, shapeNone ), 29,0,Offset=0 );
PlotShapes( IIf( Cross(0, Value2), shapeUpTriangle+ shapePositionAbove, shapeNone ), 32,0,Offset=0);
PlotShapes(IIf(Cross(myma,value2),shapeuparrow+ shapePositionAbove, shapeNone ), 12,0,Offset=myma);
PlotShapes(IIf(Cross(Value2 ,myma),shapedownarrow+ shapePositionAbove, shapeNone ),7 ,0,Offset=myma,-10);
//Plot(myma,"",5,styleLine|styleThick);
//{— Issue Alert when the Squeeze is On -———————-}
ALERT”;
//Write alerts to Interpretation window
//Ticker = Name();
//WriteIf(BBcrossDown,Ticker + " " + “BB Squeeze Alert” ,WriteIf(BBcrossUp,Ticker + " " + “BB Squeeze Is Over”,""));
//Write alerts to Alert Output window
//AlertIf(BBcrossDown,"",“BB Squeeze Alert”,0);
//AlertIf(BBcrossUp,"",“BB Squeeze Is Over”,0);
//Sound alerts
//AlertIf( BBcrossDown, “SOUND C:\\Windows\\Media\\RINGIN.WAV”, “Audio alert”, 2 );
//AlertIf( BBcrossUp, “SOUND C:\\Windows\\Media\\RINGIN.WAV”, “Audio alert”, 2 );
//Write text to screen
//ytext = 0.01;
/*
or(i=1;i<BarCount;i++)
{
If(BBcrossDown[i])
{

PlotText(“ON”,i,-ytext[i],colorWhite);
}

if(BBcrossUp[i])

{

PlotText(“OFF”,i,ytext[i],colorWhite);

}

}

*/

//PlotShapes(shapeUpArrow*BBcrossDown,colorWhite,0,0);
//PlotShapes(shapeDownArrow*BBcrossup,colorWhite,0,0);
_SECTION_END();

/SECTION_BEGIN(“KP Fast 2”);
//SetChartBkColor(ParamColor(“Panel Color”,colorLightGrey));
//SetChartBkGradientFill(ParamColor(“Upper Chart”,colorLightGrey),ParamColor(“Lower Chart”,colorLightGrey));
//tskp_fast2val1, tskp_fast2val2
dummy=E_TSKPFAST2(Open,High,Low,Close,Volume);
Plot(tskp_fast2val1,“Fast2_1”,ParamColor(“ColorUp”,colorBlue),styleLine|styleThick);
Plot( tskp_fast2val2,“Fast2_2”,ParamColor(“ColorDown”,colorRed),styleLine|styleThick);
PlotShapes(IIf(Cross(tskp_fast2val1,0),shapeDigit1+ shapePositionAbove, shapeNone ), 29,0,Offset=tskp_fast2val1,-12 );
PlotShapes(IIf(Cross(0,tskp_fast2val2),shapeDigit1+ shapePositionAbove, shapeNone ), 4,0,Offset=tskp
fast2val2,12 );
//Plot(0,"",ParamColor(“Zero Line”,colorGrey50),styleLine|styleNoLabel);
//Title =FullName();
_SECTION_END();
/

SECTION_BEGIN(“KP M Range”);
mp=0.5*(High + Low);
tightstop=E_TSKPTIGHTSTOP(High,Low,Close);
stopline=E
TSKPSTOPLINE;
Color=colorWhite;
for( i = 0; i < BarCount; i++ )
{
if( mp[i] > stopline[i] && mp[i] > tightstop[i] )
Color[i] = colorBlue;
else if( mp[i] < stopline[i] && mp[i] < tightstop[i])
Color[i] = colorRed;
else
Color[i] = colorWhite;
}
Plot(0,"",Color,styleOwnScale|styleArea|styleNoLabel,0, 90 );
Plot(7,"",Color,styleOwnScale|styleArea|styleNoLabel,0, 90 );
_SECTION_END();

SECTION_BEGIN(“KP TrendBias BackGround”);//Plot Tone
dummy = E_TSKPTRENDBIAS(High,Low,Close);
KPTB = tskp_sb;
KPTBSlow = tskp
tbxavg;
parmToneColorUp=ParamColor(“Tone Color Up”, colorLightBlue );
parmToneColorDn=ParamColor(“Tone Color Dn”, colorTan);
RibbonSize=Param(“Ribbon Size”,20,0.5,10,0.5);
Plot( RibbonSize,"",IIf(KPTB > KPTBSlow,parmToneColorUp,parmToneColorDn),styleOwnScale|styleArea|styleNoLabel,0,10);
_SECTION_END();

6. tuantai0304

This code is awesome. Thank you

Leave Comment

Please login here to leave a comment.

Back