## EMA with MOBO attached
# MOBO = Momentum breakout
declare upper;
input price = close;
input length = 13;#8
input displace = 0;
# MOBO parameters
input ColoredMobo = yes;
input ColoredFill = yes;
input MOBO_midline = no;
input MOBO_displace = 0;
input MOBO_length = 10;
input Num_Dev_Dn = -0.8;
input Num_Dev_Up = +0.8;
def AvgExp = ExpAverage(price[-displace], length); # default is an 8 bar EMA (JQ)
#AvgExp.DefineColor("Up", CreateColor( 0, 220, 0));
#AvgExp.DefineColor("Down", Color.MAGENTA);
#AvgExp.AssignValueColor(if AvgExp > AvgExp[1] and AvgExp[1] > AvgExp [2] and AvgExp[2] > AvgExp[3] and AvgExp[3] > AvgExp[4] then AvgExp.Color("Up") else if AvgExp < AvgExp[1] and AvgExp[1] < AvgExp [2] and AvgExp[2] < AvgExp[3] and AvgExp[3] < AvgExp[4] then AvgExp.Color("Down") else color.YELLOW);
#AvgExp.SetLineWeight(3);
#AvgExp.HideBubble();
def Midline = Average (data = AvgExp, MOBO_length); # the default is a 10 bar SMA of the previously calculated 8 bar EMA of close
def sDev = StDev(data = AvgExp[-MOBO_displace], length = MOBO_length);
def LowerBand = Midline + Num_Dev_Dn * sDev;
def UpperBand = Midline + Num_Dev_Up * sDev; # effectively creates an exponential Bollinger with .8 StdDev bands
def MoboStatus =
if UpperBand >= UpperBand[1] then 2 # Mobo Up
else
if LowerBand < LowerBand[1] then -2 # Mobo Down
else 0; # between the bands
rec BreakStatus = CompoundValue(1,
if BreakStatus[1] == MoboStatus or MoboStatus == 0 then BreakStatus[1]
else
if MoboStatus == 2 then 2
else -2, 0);
plot MidlineP =
if MOBO_midline then Midline
else Double.NaN;
MidlineP.SetDefaultColor(GetColor(1));
MidlineP.HideBubble();
plot UpperBandP = UpperBand;
UpperBandP.AssignValueColor (
if !ColoredMobo then Color.WHITE
else
if BreakStatus[0] == 2 then Color.green
else Color.red);
UpperBandP. SetLineWeight(1);
UpperBandP.HideBubble();
plot LowerBandP = LowerBand;
LowerBandP.AssignValueColor (
if !ColoredMobo then Color.WHITE
else
if BreakStatus[0] == 2 then Color.green
else Color.red);
LowerBandP.SetLineWeight(1);
LowerBandP.HideBubble();
# colored clouds
plot GreenUpper = if ColoredFill and BreakStatus[0] == 2 then
UpperBandP else Double.NaN;
GreenUpper.SetDefaultColor(CreateColor(0, 230, 0));
plot GreenLower = if ColoredFill and BreakStatus[0] == 2 then
LowerBandP else Double.NaN;
GreenLower.SetDefaultColor(CreateColor(0, 230, 0));
AddCloud (GreenUpper, GreenLower, Color.green, Color.RED);
plot RedUpper = if ColoredFill and BreakStatus[0] == -2 then
UpperBandP else Double.NaN;
RedUpper.SetDefaultColor(CreateColor(230, 0, 0));
plot RedLower = if ColoredFill and BreakStatus[0] == -2 then
LowerBandP else Double.NaN;
RedLower.SetDefaultColor(CreateColor(230, 0, 0));
AddCloud (RedUpper, RedLower, Color.red, Color.RED);
#end