mbarcala
Active member
I have a little situation here assigning a color on the price and for some reason I haven't be able to see what I doing wrong. Here is part of my code to see if someone can help me to understand where I'm stuck
I working with a Bollinger bands
What I trying to do is that in one option I paint the bars only when the price cross the 20EMA only and the rest gray and in the second option I just want to paint the bars when they goes over the bands in my Bollinger bands and the rest gray
any idea what I'm missing here?
I working with a Bollinger bands
Code:
input length = 20;
input colorType = {default "CrossMa", "ovBands"};
plot midBand = ExpAverage(close, length);
def dcUp = if close[1] crosses below midBand and close crosses above midBand or close crosses above midBand then 1 else 0;
def dcDn = if close[1] crosses above midBand and close crosses below midBand or close crosses below midBand then 1 else 0;
def ovUpBands = if close > UpBand1s or high > UpBand1s then 1 else 0;
def ovDnBands = if close < DnBand1s or low < DnBand1s then 1 else 0;
## Dots Direction ##
def viUpDn = if dcUp or dcDn then 1 else if viUpDn[1] == 1 and dcUp or dcDn then 1 else 0;
def debug = yes;
plot x = if !debug then Double.NAN else viUpDn;
x.Hide();
DefineGlobalColor("Blue", CreateColor(0,101,255));
DefineGlobalColor("dGray", CreateColor(50,50,50));
DefineGlobalColor("Burg", CreateColor(230,17,125));
def UpView;
def DnView;
plot diDots;
def ovUpBand;
def ovDnBand;
switch (colorType) {
case "CrossMA":
UpView = dcUp;
DnView = dcDn;
diDots = if UpView and viUpDn[-1] == 0 then plow else
if DnView and viUpDn[-1] == 0 then phigh else Double.NaN;
ovUpBand = Double.NaN;
ovDnBand = Double.NaN;
case "ovBands":
UpView = Double.NaN;
DnView = Double.NaN;
diDots = Double.NaN;
ovUpBand = ovUpBands;
ovDnBand = ovDnBands;
}
diDots.SetDefaultColor(GlobalColor("Burg"));
diDots.SetStyle(Curve.POINTS);
diDots.SetLineWeight(2);
diDots.HideTitle();
diDots.HideBubble();
AssignPriceColor(if UpView or DnView then GlobalColor("Blue") else
if ovUpBand or ovDnBand then GlobalColor("Blue") else GlobalColor("dGray"));
What I trying to do is that in one option I paint the bars only when the price cross the 20EMA only and the rest gray and in the second option I just want to paint the bars when they goes over the bands in my Bollinger bands and the rest gray
any idea what I'm missing here?