declare lower;
input length = 7;
input calcLength = 5;
input smoothLength = 3;
def o = open;
def c = close;
def data = fold i = 0 to length with s do s + (if c > GetValue(o, i) then 1 else if c < GetValue(o, i) then - 1 else 0);
def EMA5 = ExpAverage(data, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
Main.AssignValueColor(if Main > Signal then Color.GREEN else Color.GREEN);
Signal.AssignValueColor(if Main > Signal then Color.RED else Color.RED);
Signal.HideBubble();
Signal.HideTitle();
AddCloud(Main, Signal, Color.GREEN, Color.BLACK);
plot zero = if IsNaN(c) then Double.NaN else 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
plot ob = if IsNaN(c) then Double.NaN else Round(length * .7);
ob.SetDefaultColor(Color.BLUE);
ob.HideBubble();
ob.HideTitle();
plot os = if IsNaN(c) then Double.NaN else -Round(length * .7);
os.SetDefaultColor(Color.BLUE);
os.HideBubble();
os.HideTitle();
#BUBBLE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
def CrossBar = if Main crosses Signal then BarNumber() else Double.NaN;
#CLOUD---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AddCloud(ob, length, Color.black, Color.black, no);
AddCloud(-length, os, Color.black, Color.black);
#DOTS and BUBBLES---------------------------------------------------------------------------------------------------------------------------------------------------------------
plot DownSignal = if Main crosses below Signal then Signal else Double.NaN;
DownSignal.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
AddChartBubble((DownSignal) and (DownSignal), DownSignal, "S" , Color.PINK);
plot UpSignal = if Main crosses above Signal then Signal else Double.NaN;
UpSignal.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
AddChartBubble((UpSignal) and (UpSignal), UpSignal, "B" , Color.LIME);
AddLabel (yes, if Main > Signal then "BUY" + "" else "", Color.GREEN);
AddLabel (yes, if Main < Signal then "SELL" + "" else "", Color.RED);
plot MainMomentum = ExpAverage(EMA5, smoothLength);
def CrossBar2 = if MainMomentum crosses MainMomentum then BarNumber() else Double.NaN;