Price within % of Bollinger Band

BayernMustang

New member
BLUF: Scanner to find when close is within x% of Upper Bollinger Band
Looking for a scanning script to scan for when the close of a stock is within say 2% of the Upper Bollinger Band. Any help? Based off that script, I can then reverse it to find the same thing but with Lower Bollinger Bands. This strategy can help with trading with reversion to the mean sort of setups.
Thank you.
 
Solution
BLUF: Scanner to find when close is within x% of Upper Bollinger Band
Looking for a scanning script to scan for when the close of a stock is within say 2% of the Upper Bollinger Band. Any help? Based off that script, I can then reverse it to find the same thing but with Lower Bollinger Bands. This strategy can help with trading with reversion to the mean sort of setups.
Thank you.

here is a lower test study, that i think should work for a scan.
it plots a value of 0 or 1, depending if close is near the upper bb line.

i copied the code from BollingerBands
replaced plots with def
added an input to select a desired percent

load this as a lower study and load BollingerBands in upper chart, and test it with different %'s.

Code:
...
BLUF: Scanner to find when close is within x% of Upper Bollinger Band
Looking for a scanning script to scan for when the close of a stock is within say 2% of the Upper Bollinger Band. Any help? Based off that script, I can then reverse it to find the same thing but with Lower Bollinger Bands. This strategy can help with trading with reversion to the mean sort of setups.
Thank you.

here is a lower test study, that i think should work for a scan.
it plots a value of 0 or 1, depending if close is near the upper bb line.

i copied the code from BollingerBands
replaced plots with def
added an input to select a desired percent

load this as a lower study and load BollingerBands in upper chart, and test it with different %'s.

Code:
# near_bb_upper_00

#https://usethinkscript.com/threads/price-within-of-bollinger-band.15007/
#Price within % of Bollinger Band

declare lower;

input upper_line_near_percent = 2.0;

# BollingerBands
# TD Ameritrade IP Company, Inc. (c) 2007-2023
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;

def sDev = stdev(data = price[-displace], length = length);

def MidLine = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;

#LowerBand.SetDefaultColor(GetColor(0));
#MidLine.SetDefaultColor(GetColor(1));
#UpperBand.SetDefaultColor(GetColor(5));


# positive above upper , negative below upper
def diffper = (100*(close - UpperBand)/UpperBand);
def nearupper = (absvalue(diffper) <= upper_line_near_percent);

plot zu = nearupper;

#-----------------------
input test1 = no;
addchartbubble(test1, 0.5, diffper, color.yellow, yes);

#
 
Solution

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

# BollingerBands # TD Ameritrade IP Company, Inc. (c) 2007-2023 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; def sDev = stdev(data = price[-displace], length = length); def MidLine = MovingAverage(averageType, data = price[-displace], length = length); def LowerBand = MidLine + num_Dev_Dn * sDev; def UpperBand = MidLine + num_Dev_Up * sDev; #LowerBand.SetDefaultColor(GetColor(0)); #MidLine.SetDefaultColor(GetColor(1)); #UpperBand.SetDefaultColor(GetColor(5)); # positive above upper , negative below upper def diffper = (100*(close - UpperBand)/UpperBand); def nearupper = (absvalue(diffper) <= upper_line_near_percent); plot zu = nearupper; #----------------------- input test1 = no; addchartbubble(test1, 0.5, diffper, color.yellow, yes); #
Thank you so much! This is exactly what I was looking for. I wish I had your skills. Thank you again.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
416 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