_SECTION_BEGIN("BB-MACD");
//--Created by KelvinHand
iMACD=Null; iMidBB=Null;
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack), colorLightGrey);
MACDMethod = ParamList("MACD.Mode", "SMA|EMA", 1);
r1 = Param("Macd.FastPeriod", 12);
r2 = Param("Macd.SlowPeriod", 26);
BBMethod = ParamList("BB.Mode", "SMA|EMA");
r3 = Param("BB.Period", 10);
r4 = Param("BB.StdDev", 1.0, 1,10, 0.1);
ShowMACDLine = ParamToggle("Show MACD Line?", "No|Yes");
ShowMidBB= ParamToggle("Show Mid BB?", "No|Yes", 1);
ShowOuterBB = ParamToggle("Show Upr/Lwr BB ?", "No|Yes", 1);
sShapeBtwBB = ParamList("Shape Inside BB", "Small|Big", 1);
cMacdLine=ParamColor("MACD Line", colorOrange);
cUprBB = ParamColor("BB.Upper", colorBlueGrey);
cLwrBB = ParamColor("BB.Lower", colorBlueGrey);
cMacdGeUprBB = ParamColor("Macd>=UprBB", colorBrightGreen);
cMacdLeLwrBB = ParamColor("Macd<=LwrBB", ColorRGB(255,0,255));
cMacdLtUprBB = ParamColor("Macd<=UprBB", colorRed);
cMacdGtLwrBB = ParamColor("Macd>=LwrBB", colorDarkGreen);
cZLUp = ParamColor("Macd>0-Line", ColorRGB(0,0,140));
cZLDn = ParamColor("Macd<0-Line", ColorRGB(130,0,0));
if (MACDMethod=="EMA")
iMACD= EMA(C,r1)-EMA(C,r2);
else
iMACD= MA(C,r1)- MA(C,r2);
m1 = Ref(iMACD, -1);
if (BBMethod=="EMA")
iMidBB = EMA(iMACD,r3);
else
iMidBB = MA(iMACD,r3);
SD = StDev( iMACD, r3);
BBtop= iMidBB + r4*sD;
BBbot= iMidBB - r4*sD;
if (ShowMACDLine) Plot(iMACD,"",cMacdLine);
ThisColor = IIf(iMACD>=BBtop AND iMACD>=m1, cMacdGeUprBB,
IIf(iMACD<=BBbot AND iMACD<=m1, cMacdLeLwrBB,
IIf(iMACD>iMidBB, cMacdLtUprBB, cMacdGtLwrBB)));
Plot(iMACD,"MACD", ThisColor,styleDots|styleNoLine);
if (sShapeBtwBB=="Big")
{
ThisShape = IIf(iMACD>BBtop, shapeNone,
IIf(iMACD<BBbot, shapeNone,
shapeSmallCircle));
PlotShapes( ThisShape, ThisColor,0,Null, 0 );
}
if (ShowMidBB)
Plot(iMidBB,"MidBB", colorDarkGrey, styleDashed|styleNoLabel);
if (ShowOuterBB)
{
Plot(BBtop,"UprBB",cUprBB, styleNoLabel);
Plot(BBbot,"LwrBB",cLwrBB, styleNoLabel);
}
Plot(0,"", IIf(iMACD>=0, cZLUp, cZLDn), styleNoLabel);
RequestTimedRefresh( 0 );
_SECTION_END();