petergluis
Active member
I figured out how to add cloud colors to show uptrends and downtrends.
Ruby:
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;
input fill= yes;
def sDev = stdev(data = price[-displace], length = length);
plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;
LowerBand.SetDefaultColor(GetColor(0));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));
def nan = Double.NaN;
def Chg = If((UpperBand > UpperBand[1] and LowerBand > LowerBand[1]), 1, If((UpperBand < UpperBand[1] and LowerBand < LowerBand[1]), -1, 0));
def Hold = CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp = if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp = if fill and Hold[0] == 1 then upperband else nan;
def LBDn = if fill and Hold[0] == -1 then lowerband else nan;
def UBDn = if fill and Hold[0] == -1 then upperband else nan;
DefineGlobalColor("Cloud Up", Color.magenta);
DefineGlobalColor("Cloud Dn", Color.green);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
Last edited by a moderator: