Here is the code. Notice how it plots multiple arrows up before it plots a down arrow. Only need an up arrow the first time it closes above the upper band when preceded by a close below the lower band. The previous close below could have been 1 or more candles prior. Just need an arrow up the first instance above and an arrow down the first instance below. Currently it plots multiple arrows down in a row before it ever switches side. Only need to see the first time the side switches for my filter. I was thinking maybe when it closes above the upper band making a variable that = 1. And when it closes below the lower channel making a variable that = 2. Then I could do an if then statement that says if it closes above the upper band and the variable = 2 then draw arrow up else dont draw duplicate arrows. And a statement that says if it closes below the lower band and the variable = 1 then draw a down arrow else dont draw duplicate arrows. Just not sure about the syntax. Thank you for looking at this.
declare upper;
input price = close;
#200sma is another filter to later be used. I can program this part with an AND statement
#input length = 200;
input displace = 0;
input showBreakoutSignals = no;
#plot SMA = Average(price[-displace], length);
input length = 20;
input Num_Dev_Dn = -1.0;
input Num_Dev_up = 1.0;
input averageType = AverageType.Simple;
def sDev = stdev(data = price[-displace], length = length);
def 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));
input Bollinger_length = 20;
input Bollinger_deviations = 1;
def bb_upper = BollingerBands(length = Bollinger_length, "num dev dn" = -Bollinger_deviations, "num dev up" = Bollinger_deviations).UpperBand;
def bb_lower = BollingerBands(length = Bollinger_length, "num dev dn" = -Bollinger_deviations, "num dev up" = Bollinger_deviations).LowerBand;
def c = close;
plot up_indicator = if c crosses above bb_upper and close then LOW else double.nan;
plot dn_indicator = if c crosses below bb_lower then HIGH else double.nan;
up_indicator.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
up_indicator.SetLineWeight(2);
up_indicator.SetDefaultColor(color.green);
dn_indicator.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
dn_indicator.SetLineWeight(2);
dn_indicator.SetDefaultColor(color.red);
@Butler
you can use the
crosses above or
crosses below functions with the two (band and close) and get just the points where it was below the previous bar and above this bar.
I think that's the code I have above somewhere, but I could be wrong. I try to code exactly what people ask for, whether it's what I think they want or not. Just part of having worked as a developer for a long time. Can you post your code and I'll try to tell you why it's behaving the way it is rather than the way you expect it to be?
-mashume