Price crosses Bollinger Bands

maston21

Member
Any way to take this script and take out the RSI portion? Just need the indicator to signal when price crosses or touches the upper or lower Bollinger Bands regardless of what RSI is. Price does not have to close above/below the bands, just needs to cross or touch them. Any help would be greatly appreciated!

#bb_rsi_colors

#https://usethinkscript.com/threads/bollinger-band-with-rsi.17083/
#Bollinger Band with RSI

#Indicator:
#Bollinger Band Setting 30 with 2 deviation.
#Regular RSI.

#Criteria:
#for Short:
#When the price is over the bollinger band top and the RSI is over 70 then assign a RED candles and plot a red arrow.

#for LONG:
#When the price is under the bollinger band bottom and the RSI is under 30 then assign a Green candles an plot a green arrow.
#if is not either criteria keep the candles gray color.

def na = double.nan;
def bn = barnumber();
input price = close;

input color_the_bars = yes;
input show_arrows = yes;

#-----------------------------
# BB
#input price = close;
#input displace = 0;
input bb_length = 30;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input bb_avg_type = AverageType.SIMPLE;
def sDev = StDev(price, bb_length);

def MidLine = MovingAverage(bb_avg_type, price, bb_length);
def LowerBand = MidLine + Num_Dev_Dn * sDev;
def UpperBand = MidLine + Num_Dev_up * sDev;

input show_bb_lines = yes;
plot zbbup = if show_bb_lines then upperband else na;
plot zbbmid = if show_bb_lines then midline else na;
plot zbblo = if show_bb_lines then lowerband else na;
zbbup.SetDefaultColor(GetColor(5));
zbbmid.SetDefaultColor(GetColor(1));
zbblo.SetDefaultColor(GetColor(0));

#-------------------------------
# rsi
input rsi_len = 14;
input rsi_over_bought = 70;
input rsi_over_Sold = 30;
input rsi_avg_type = AverageType.WILDERS;
def NetChgAvg = MovingAverage(rsi_avg_type, price - price[1], rsi_len);
def TotChgAvg = MovingAverage(rsi_avg_type, AbsValue(price - price[1]), rsi_len);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

#------------------------------

def long_rule1 = (close < lowerband);
def long_rule2 = (rsi < rsi_over_Sold);

def short_rule1 = (close > upperband);
def short_rule2 = (rsi > rsi_over_bought);

def long = long_rule1 and long_rule2;
def short = short_rule1 and short_rule2;

#------------------------------

def y = 0.002;
plot zlong = if show_arrows and long then (low * (1 - y)) else na;
zlong.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zlong.SetDefaultColor(Color.green);
zlong.setlineweight(1);
zlong.hidebubble();

plot zshort = if show_arrows and short then (high * (1 + y)) else na;
zshort.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zshort.SetDefaultColor(Color.red);
zshort.setlineweight(1);
zshort.hidebubble();

#------------------------------

AssignPriceColor(if !color_the_bars then color.current
else if long then color.green
else if short then color.red
else color.gray);
 
Last edited:
Solution
Any way to take this script and take out the RSI portion? Just need the indicator to signal when price crosses or touches the upper or lower Bollinger Bands regardless of what RSI is. Price does not have to close above/below the bands, just needs to cross or touch them. Any help would be greatly appreciated!

try this
Code:
#bb_rsi_colors

#https://usethinkscript.com/threads/bollinger-band-with-rsi.17083/
#Bollinger Band with RSI

#Indicator:
#Bollinger Band Setting 30 with 2 deviation.
#Regular RSI.

#Criteria:
#for Short:
#When the price is over the bollinger band top and the RSI is over 70 then assign a RED candles and plot a red arrow.

#for LONG:
#When the price is under the bollinger band bottom and the RSI is under 30...
Any way to take this script and take out the RSI portion? Just need the indicator to signal when price crosses or touches the upper or lower Bollinger Bands regardless of what RSI is. Price does not have to close above/below the bands, just needs to cross or touch them. Any help would be greatly appreciated!

try this
Code:
#bb_rsi_colors

#https://usethinkscript.com/threads/bollinger-band-with-rsi.17083/
#Bollinger Band with RSI

#Indicator:
#Bollinger Band Setting 30 with 2 deviation.
#Regular RSI.

#Criteria:
#for Short:
#When the price is over the bollinger band top and the RSI is over 70 then assign a RED candles and plot a red arrow.

#for LONG:
#When the price is under the bollinger band bottom and the RSI is under 30 then assign a Green candles an plot a green arrow.
#if is not either criteria keep the candles gray color.

def na = double.nan;
def bn = barnumber();
input price = close;

input color_the_bars = yes;
input show_arrows = yes;

#-----------------------------
# BB
#input price = close;
#input displace = 0;
input bb_length = 30;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input bb_avg_type = AverageType.SIMPLE;
def sDev = StDev(price, bb_length);

def MidLine = MovingAverage(bb_avg_type, price, bb_length);
def LowerBand = MidLine + Num_Dev_Dn * sDev;
def UpperBand = MidLine + Num_Dev_up * sDev;

input show_bb_lines = yes;
plot zbbup = if show_bb_lines then upperband else na;
plot zbbmid = if show_bb_lines then midline else na;
plot zbblo = if show_bb_lines then lowerband else na;
zbbup.SetDefaultColor(GetColor(5));
zbbmid.SetDefaultColor(GetColor(1));
zbblo.SetDefaultColor(GetColor(0));


#------------------------------

def long_rule1 = (close < lowerband);


def short_rule1 = (close > upperband);


def long = high>LowerBand and low<lowerband;
def short =  high>upperband and low<upperband;

#------------------------------

def y = 0.002;
plot zlong = if show_arrows and long then (low * (1 - y)) else na;
zlong.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zlong.SetDefaultColor(Color.green);
zlong.setlineweight(1);
zlong.hidebubble();

plot zshort = if show_arrows and short then (high * (1 + y)) else na;
zshort.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zshort.SetDefaultColor(Color.red);
zshort.setlineweight(1);
zshort.hidebubble();

#------------------------------

AssignPriceColor(if !color_the_bars then color.current
else if long then color.green
else if short then color.red
else color.gray);



1717349141812.png
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
252 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top