Join useThinkScript to post your question to a community of 21,000+ developers and traders.
close is greater than BollingerBands("num dev up" = 1.0)."UpperBand" and close is less than BollingerBands()."UpperBand"
Is there a way to scan, if a bollinger band is trending upward, (eg midline, midline[2], midline[4] and midline[6] are all trending up) appreciate it.
#Out of Bounds
def sDev = StDev(close, 21);
def MidLine = Average(close, 21);
def UpperBand = MidLine + 2 * sDev;
def LowerBand = MidLine - 2 * sDev;
plot OOB = if close > UpperBand then Round(close - UpperBand, 2) else if close < LowerBand then Round(close - LowerBand, 2) else Double.NaN;
AssignBackgroundColor(if !isnan(oob) then color.white else color.gray);
OOB.assignvalueColor(if !isnan(oob) then color.black else color.gray);
input aggregationPeriod=AggregationPeriod.day;
def data = close(period = aggregationPeriod);
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;
def sDev = stdev(data = data[-displace], length = length);
plot MidLine = MovingAverage(averageType, data = data[-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));
plot Upper = reference BollingerBands.UpperBand;
Upper.AssignValueColor(if Upper > Upper[1] then Color.UPTICK else Color.RED);
plot Middle = reference BollingerBands.MidLine;
Middle.AssignValueColor(if Middle > Middle[1] then Color.UPTICK else Color.RED);
plot Lower = reference BollingerBands.LowerBand;
Lower.AssignValueColor(if Lower > Lower[1] then Color.UPTICK else Color.RED);
I just noticed I didn't update each line to color based on its own being higher or lower. Each was looking at the Upper band. Fixing in original post.Thanks so much!
It did look a little funny, but I wasn't complaining. I'll use the update! Thanks so much.I just noticed I didn't update each line to color based on its own being higher or lower. Each was looking at the Upper band. Fixing in original post.
# Alert
Alert(Signal, "Bollinger Alert", Alert.Bar, Sound.Chimes);
can be possible to have a dot signal every time the price hit the over sold and over buy zone?Ruby:plot Upper = reference BollingerBands.UpperBand; Upper.AssignValueColor(if Upper > Upper[1] then Color.UPTICK else Color.RED); plot Middle = reference BollingerBands.MidLine; Middle.AssignValueColor(if Middle > Middle[1] then Color.UPTICK else Color.RED); plot Lower = reference BollingerBands.LowerBand; Lower.AssignValueColor(if Lower > Lower[1] then Color.UPTICK else Color.RED);
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.