Perfect MACD Indicator With Buy Sell Indication


Perfect MACD Indicator With Buy Sell Indication
Perfect MACD Indicator With Buy Sell Indication

//www.aflcode.com
var1=MA( Avg , 34);
var2=MA( Avg,5);
var3=var2-var1;
var4=MA(var3-MA(var3,5),5);

up = Var4 > Ref(Var4,-1);
down = Var4 < Ref(Var4,-1);

Graph0=var4;
Graph0Style=2+4;
Graph1=Wilders(var4,5);
Graph1Style=5;
Graph0Name = "AC";
Graph0BarColor = IIf(up, colorGreen, colorRed);


up = Var4 > Ref(Var4,-1);
down = Var4 < Ref(Var4,-1);

//3 bars buy when in positive territory:
AllAbove0 = Ref(Var4,-3) > 0 AND Ref(Var4,-2) > 0 AND Ref(Var4,-1) > 0;
SellA = Ref(up,-3) AND Ref(down,-2) AND Ref(down,-1) AND down AND AllAbove0;

//2 bars sell. If in negative territory or crossed below 0:
AllBelow0 = Ref(Var4,-3) < 0 AND Ref(Var4,-2) < 0 AND Ref(Var4,-1) > 0;
CrossBelow0 = (Ref(Var4,-2) > 0 AND Ref(Var4,-1) < 0) OR (Ref(Var4,-1) > 0 AND Var4 < 0);
SellB = Ref(up,-2) AND Ref(down,-1) AND down AND (AllBelow0  OR CrossBelow0);

CrossAbove0 = (Ref(Var4,-2) < 0 AND Ref(Var4,-1) > 0) OR (Ref(Var4,-1) < 0 AND Var4 > 0);
//3 bars buy when in negative territory:
BuyA = Ref(down,-3) AND Ref(up,-2) AND Ref(up,-1) AND up AND AllBelow0;
//2 bars buy. If in positive territory or crossed above 0:
BuyB = Ref(down,-2) AND Ref(up,-1) AND up AND (AllAbove0 OR CrossAbove0);

Buy = BuyA OR BuyB;
Sell = SellA OR SellB;

PlotShapes( IIf(Buy ,shapeUpArrow,0) ,colorGreen, 0, IIf(Var4 < 0, Var4, 0),-12);
PlotShapes( IIf(Sell ,shapeDownArrow,0) ,colorRed, 0, IIf(Var4 < 0, Var4, 0),12);

//Commentary
WriteIf(Buy, "Place Buy Stop to buy 1 unit if price rises to " + WriteVal(H+0.01)+" or higher. (AC+)",
WriteIf(Sell, "Place Sell Stop to sell 1 unit if price falls to " + WriteVal(L-0.01)+" or lower. (AC-)",""));

Previous
Next Post »