declare lower;
input length = 20;
input SigLength = 3;
input arrows = 0;
input dotsize = 3;
input APC = 0;
def smooth = ExpAverage(close, length);
plot emaroc = 100 * (smooth - smooth[5]) / smooth[5];
emaroc.setdefaultColor(Color.Cyan);
emaroc.SetLineWeight(2);
emaroc.HideBubble();
Plot Signal = ExpAverage(emaroc,Siglength);
Signal.SetdefaultColor(Color.Magenta);
signal.SetLineWeight(2);
plot cline = 0;
cline.SetDefaultColor(Color.GRAY);
AddCloud(emaroc,Signal,Color.Cyan,Color.Magenta);
def Mmax= Max(emaroc,Signal);
def MMin= Min(emaroc,Signal);
AddCloud(MMin,0,Color.green,Color.Black);
AddCloud(Mmax,0,Color.Black,Color.Red);
Def Con1 = emaroc >= 0;
Def Con2 = emaroc < 0;
Def Con3 = emaroc > emaroc [1];
Def Con4 = emaroc < emaroc [1];
Plot BullRise = If Con1 and Con3 then MMin else 0;
BullRise.SetPaintingStrategy(PaintingStrategy.Histogram);
BullRise.SetDefaultColor(Color.Green);
BullRise.SetLineWeight(3);
Plot BullFall = if Con1 and Con4 then MMin else 0;
BullFall.SetPaintingStrategy(PaintingStrategy.Histogram);
BullFall.SetDefaultColor(Color.Dark_Green);
BullFall.SetLineWeight(3);
Plot BearFall = if Con2 and Con4 then MMax else 0;
BearFall.SetPaintingStrategy(PaintingStrategy.Histogram);
BearFall.SetDefaultColor(Color.Dark_Red);
BearFall.SetLineWeight(3);
Plot BearRise = if Con2 and Con3 then Mmax else 0;
BearRise.SetPaintingStrategy(PaintingStrategy.Histogram);
BearRise.SetDefaultColor(Color.Red);
BEarRise.SetLineWeight(3);
Plot UZ = Average(emaroc,34) + (1.3185*StDev(emaroc,34));
UZ.SetPaintingStrategy(PaintingStrategy.Line);
UZ.SetLineWeight(2);
UZ.SetDefaultColor(Color.Yellow);
Plot LZ = Average(emaroc,34) - (1.3185*StDev(emaroc,34));
LZ.SetPaintingStrategy(PaintingStrategy.Line);
LZ.SetLineWeight(2);
LZ.SetDefaultColor(Color.Yellow);
#ARROWS
plot ArrowDown = if arrows and (emaroc Crosses below Signal) then Signal else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Magenta);
ArrowDown.setLineWeight(dotsize);
plot ArrowUp = if arrows and (emaroc crosses above Signal) then signal else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Cyan);
ArrowUp.setLineWeight(dotsize);
plot ArrowDown2 = if arrows and (emaroc Crosses below 0) then 0 else double.nan;
ArrowDown2.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown2.setDefaultColor(color.Red);
ArrowDown2.setLineWeight(dotsize);
plot ArrowUp2 = if arrows and (emaroc crosses above 0 ) then 0 else double.nan;
ArrowUp2.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp2.setDefaultColor(color.Blue);
ArrowUp2.setLineWeight(dotsize);
plot ArrowDown3 = if arrows and (emaroc Crosses below UZ) then UZ else double.nan;
ArrowDown3.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown3.setDefaultColor(color.Yellow);
ArrowDown3.setLineWeight(dotsize);
plot ArrowUp3 = if arrows and (emaroc crosses above LZ ) then LZ else double.nan;
ArrowUp3.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp3.setDefaultColor(color.Yellow);
ArrowUp3.setLineWeight(dotsize);
AssignPriceColor( if APC ==1 and emaroc >= signal then Color.Cyan else if APC == 1 and emaroc < Signal then Color.Magenta else If APC ==2 and emaroc >=0 then Color.Green else If APC ==2 and emaroc <0 then Color.Red else Color.Current);