a namespace declaration is expected on line 3
a using clause must proceed all the other namespace elements except extern alias declarations on line 5-6 below...
//[LegacyColorValue = true];
// by PepperPhd
{ General idea is to provide clarity of the location of the MACD dot (above/below BB band) and whether the MACD is rising/falling.
Also, provides insight intothe location of a MACD dot in a Higher Time Frame (by using MACD2Factor).
Summary...........
MACD Dot color:
- GREEN - rising and ABOVE upper band
- DarkCyan - Rising
- DarkMagenta - Falling
- RED - Falling and BELOW lower band
BB Line Color ... matches the MACD dot lcoation on a synthetic higher time frame (e.g., a 110 tick chart with
a MACD2Factor of 4, will simulate the MACD dot location on a 440 tick chart).
- GREEN - ABOVE upper band
- Yellow (was DarkCyan) - between upper band and center line
- Yellow (was DarkMagenta) - between lower band and center line
- Black - BELOW lower band
Zero Line:
- MACD dot location toggles between above/below
- Thickening will occur if MACD dot location on Higher Time Frame is also on same side of zero line
BB Center Line:
- MACD dot location toggles between above/below centerline
- Thickening will occur if Higher Time Frame MACD Dot separation is accelerating in direction of MACD trend
BB Fill Color:
-- BB will have a fill line when MACD dot is above/below band
}
Inputs: Price( Close), FastMA(12), SlowMA(26), Length( 10), BBlength(10), NumDevs( 1), NumDevsDn( -1),
MACD2factor(2), // creates synthetic higher time frame (e.g. x4)
HistoPlot(true),
ZeroXadj(1), ZeroXColor(White), // Zero Line Cross Display
BBabove(green), BBmidup(darkcyan), BBmidlo(darkmagenta), BBbelow(black), // BB colors
DecAdj(100), // adjust value of MACD price
Displace( 0) ;
Vars: MACDprice(0), Avg( 0 ), SDev( 0 ), LowerBand( 0 ), UpperBand( 0 ),
MACDprice2(0), Avg2( 0 ), SDev2( 0 ), LowerBand2( 0 ), UpperBand2( 0 ) ;
// Regular time frame
MACDprice = MACD(Price, FastMA, SlowMA)*DecAdj;
Avg = Xaverage( MACDprice, Length ) ;
SDev = StdDev( MACDprice, BBlength) ;
UpperBand = Avg + SDev * NumDevs ;
LowerBand = Avg - SDev * NumDevs ;
{
// Next higher time frame
MACDprice2 = MACD(Price, FastMA*MACD2factor, SlowMA*MACD2factor);
Avg2 = Xaverage( MACDprice2, Length*MACD2factor ) ;
SDev2 = StdDev( MACDprice2, BBlength*MACD2factor) ;
UpperBand2 = Avg2 + SDev2 * NumDevs ;
LowerBand2 = Avg2 - SDev2 * NumDevs ;
}
// Basic Plots
if Displace >= 0 or CurrentBar > AbsValue( Displace ) then
begin
Plot1 [Displace]( MACDprice, "MACDdot" ) ;
Plot2 [Displace]( 0, "Zcross" ) ;
Plot3 [Displace]( MACDprice, "MACDshadow");
Plot23[Displace]( UpperBand, "UpperBand" ) ;
Plot24[Displace]( LowerBand, "LowerBand" ) ;
Plot5 [Displace]( MACDprice, "MACDline") ;
Plot6 [Displace]( Avg, "MACDavg");
End;
// MACD Trend Color Plots
If MACDprice > MACDprice[1] then // MACD dot going up, but below Upper Band
SetPlotColor(1,BBmidup)
else if MACDprice < MACDprice[1] then // MACD dot going down, but above Lower Band
setplotcolor(1,BBmidlo);
If MACDprice > MACDprice[1] AND MACDprice > UpperBand // MACD dot going up, AND above Upper Band
then setplotColor(1,BBabove);
If MACDprice < MACDprice[1] AND MACDprice < LowerBand // MACD dot going down, AND below Lower Band
then setplotColor(1,BBbelow);
// BB Color Plots - Changes color of BB based on location of MACD on higher timeframe
If MACDprice2 > UpperBand2 then begin
SetPlotColor(23,BBabove);
SetPlotColor(24,BBabove);
end;
if MACDprice2 < UpperBand2 AND MACDprice2 > Avg2 then begin
setplotcolor(23,BBmidup);
setplotcolor(24,BBmidup);
end;
If MACDprice2 < LowerBand2 then begin
setplotColor(23,BBbelow);
setplotColor(24,BBbelow);
end;
If MACDprice2 > LowerBand2 AND MACDprice2 < Avg2 then begin
setplotColor(23,BBmidlo);
setplotColor(24,BBmidlo);
end;
// BB plot acceleration - thickens BB center line if higher timeframe is accelerating in same trend direction
If MACDprice2>UpperBand2 AND (MACDprice2-Upperband2)[0] > (MACDprice2-Upperband2)[1] then
SetPlotWidth(6,3);
If MACDprice2<LowerBand2 AND (MACDprice2-LowerBand2)[0] < (MACDprice2-LowerBand2)[1] then
SetPlotWidth(6,3);
// Zero Line Color Plot
If Plot1 < 0 then
SetPlotColor(2,darkblue);
If Plot1 > 0 then
SetPlotColor(2,darkblue);
{
// Zero Line Cross over Plots
If Plot1[0] crosses under 0 then begin
Plot2[0](-_tickadj(ZeroXadj),"Zcross",ZeroXColor,default,2);
Plot2[1](0,"Zcross",ZeroXColor,default,2);
Alert("Go Short Zero Cross");
end else begin
if Plot1 crosses over 0 then begin
Plot2[0](_tickadj(ZeroXadj),"Zcross",ZeroXColor,default,2) ;
Plot2[1](0,"Zcross",ZeroXColor,default,2);
Alert("Go Long Zero Cross");
End; End;
}
// BB Histo Plot - plots color trend when MACD is outside BB
If HistoPlot = true
and (MACDprice[1] > UpperBand[1] OR MACDprice[1] < LowerBand[1]) then begin
Plot31[1](UpperBand[1],"HistoUpper");
Plot32[1](LowerBand[1],"HistoLower");
end;
If MACDprice < Avg then begin
SetPlotColor(31,BBbelow);
SetPlotColor(32,BBbelow);
end;
If MACDprice > Avg then begin
SetPlotColor(31,BBabove);
SetPlotColor(32,BBabove);
end;
// Avg Plot - Centerline of BB
If MACDprice < Avg then
SetPlotColor(6,BBbelow);
If MACDprice > Avg then
SetPlotColor(6,BBabove);
{
// ....................... Higher Time Frame Plots ........................
// Zero Line Color Plot of Higher Time Frame - Thickens Zline if MACD of HTF is on same side
If MACDprice2 < 0 AND MACDprice < 0 then
SetPlotWidth(2,4);
If MACDprice2 > 0 AND MACDprice > 0 then
SetPlotWidth(2,4);
}
Comment