Bollinger Bands Percentile+ STD Channels [Algo Alert] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
3K2ulPU.png


Author Message:
The "Bollinger Bands Percentile (BBPct) + STD Channels" mean reversion indicator, developed by Algo_Alert, is a technical analysis tool designed to analyze price positions using Bollinger Bands and Standard Deviation Channels (STDC). The combination of these two indicators reinforces a stronger reversal signal. BBPct calculates the percentile rank of the price's standard deviation relative to a specified lookback period. Standard deviation channels operate by utilizing a moving average as the central line, with upper and lower lines equidistant from the average based on the market's volatility, helping to identify potential price boundaries and deviations.
More details : https://www.tradingview.com/v/Txv4QC95/

CODE:

CSS:
#https://www.tradingview.com/v/Txv4QC95/
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Algo_Alert
#Bollinger Bands Percentile (BBPct) + STD Channels [Algo Alert]
#indicator(shorttitle="? BBPCT% [Algo Alert]", title="? Bollinger Bands Percent", overlay=false)
# Converted by Sam4Cok@Samer800    - 07/2023
declare lower;
#//Symmetrical Standard Deviation Channels

#//BBPCT
input colorBars = yes;
input BollingerBandLength = 20;    # 'Bollinger Band'
input Source = close;              # "Source"
input bbMultiplier = 2.0;          # "Multiplier"
input showBbStdevHistogram = no;   # 'Show Bollinger Band Stdev %'

def na = Double.NaN;
def last = isNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
DefineGlobalColor("up", CreateColor(0,255,187));
DefineGlobalColor("dn", CreateColor(255,0,0));
DefineGlobalColor("histup", CreateColor(38,166,154));
DefineGlobalColor("histdn", CreateColor(178,223,219));

def upper1 = close + 0.05 * close;
def lower1 = close - 0.05 * close;
def stdL = close > lower1;
def stdS = close < upper1;

def basis = Average(Source, BollingerBandLength);
def dev   = bbMultiplier * StDev(Source, BollingerBandLength);

def upper = basis + dev;
def lower = basis - dev;
def positionBetweenBands = 100 * (Source - lower) / (upper - lower);
def hist = 100 * dev/close;

def crossUp = (positionBetweenBands Crosses above -8) and stdL;
def crossDn = (positionBetweenBands Crosses Below 108) and stdS;

def upCol = positionBetweenBands > 50;
def upCol1 = positionBetweenBands> 95;
def upCol2 = positionBetweenBands> 110;
def dnCol = positionBetweenBands <= 50;
def dnCol1 = positionBetweenBands<= 25;
def dnCol2 = positionBetweenBands<= 10;

def obupper = if last then na else pos;#if showBbStdev then 1 else pos;
def oblower = if last then na else if showBbStdevHistogram then 0.65 else 110;
def obmid = if last then na else if showBbStdevHistogram then 0.4 else 95;
def osupper = if last then na else if showBbStdevHistogram then 0.1 else 10;
def oslower = if last then na else neg;#then 0 else neg;
def osmid = if last then na else if showBbStdevHistogram then 0.25 else 25;

plot SigUp = if showBbStdevHistogram then na else if crossUp then 5 else -10;
plot SigDn = if showBbStdevHistogram then na else if crossDn then 115 else 130;
SigUp.SetLineWeight(2);
SigDn.SetLineWeight(2);
SigUp.SetDefaultColor(Color.CYAN);
SigDn.SetDefaultColor(Color.MAGENTA);

plot SqUp = if showBbStdevHistogram then if crossUp then hist+0.05 else na else na;
plot SqDn = if showBbStdevHistogram then if crossDn then hist+0.05 else na else na;
SqUp.SetLineWeight(2);
SqDn.SetLineWeight(2);
SqUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
SqDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
SqUp.SetDefaultColor(Color.GREEN);
SqDn.SetDefaultColor(Color.RED);

plot z = if showBbStdevHistogram then na else positionBetweenBands;
z.AssignValueColor(if upCol then GlobalColor("up") else GlobalColor("dn"));
z.SetLineWeight(2);

plot Histo = if showBbStdevHistogram then hist else na;
Histo.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Histo.AssignValueColor( if hist>hist[1] then GlobalColor("histup") else GlobalColor("histdn"));

plot mid = if last or showBbStdevHistogram then na else 50;
mid.SetDefaultColor(Color.GRAY);
mid.SetStyle(Curve.SHORT_DASH);

AssignPriceColor(if !colorBars then Color.CURRENT else if upCol then
                 if upCol1 then Color.GREEN else Color.DARK_GREEN else
                 if dnCol1 then Color.RED else Color.DARK_RED);

AddCloud(obupper, oblower, Color.RED);#
AddCloud(oblower, obmid, Color.DARK_RED);
AddCloud(osupper, oslower, Color.GREEN, Color.GREEN, showBbStdevHistogram);
AddCloud(osmid, osupper, Color.DARK_GREEN);

AddCloud(if upCol  then z else na, mid, Color.DARK_GREEN);
AddCloud(if upCol1 then z else na, mid, Color.DARK_GREEN);
AddCloud(if upCol2 then z else na, mid, Color.DARK_GREEN);

AddCloud(if dnCol then mid else na,  z, Color.DARK_RED);
AddCloud(if dnCol1 then mid else na, z, Color.DARK_RED);
AddCloud(if dnCol2 then mid else na, z, Color.DARK_RED);


#-- END of CODE
 

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

Would you be able to add an alert for this? I am specifically looking for the
Sigup and Sigdwn signals alert. I tried monkeying myself but couldn't get
it to work. Thanks!

UPDATE:
Nevermind I figured it out by asking Bing AI - this is what it came up with:
# Alert
alert(crossUp, "Crossed above -8", Alert.BAR, Sound.Chimes);
alert(crossDn, "Crossed below 108", Alert.BAR, Sound.Chimes);

it seems to be working fine.
 
Last edited by a moderator:
3K2ulPU.png


Author Message:
The "Bollinger Bands Percentile (BBPct) + STD Channels" mean reversion indicator, developed by Algo_Alert, is a technical analysis tool designed to analyze price positions using Bollinger Bands and Standard Deviation Channels (STDC). The combination of these two indicators reinforces a stronger reversal signal. BBPct calculates the percentile rank of the price's standard deviation relative to a specified lookback period. Standard deviation channels operate by utilizing a moving average as the central line, with upper and lower lines equidistant from the average based on the market's volatility, helping to identify potential price boundaries and deviations.
More details : https://www.tradingview.com/v/Txv4QC95/

CODE:

CSS:
#https://www.tradingview.com/v/Txv4QC95/
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Algo_Alert
#Bollinger Bands Percentile (BBPct) + STD Channels [Algo Alert]
#indicator(shorttitle="? BBPCT% [Algo Alert]", title="? Bollinger Bands Percent", overlay=false)
# Converted by Sam4Cok@Samer800    - 07/2023
declare lower;
#//Symmetrical Standard Deviation Channels

#//BBPCT
input colorBars = yes;
input BollingerBandLength = 20;    # 'Bollinger Band'
input Source = close;              # "Source"
input bbMultiplier = 2.0;          # "Multiplier"
input showBbStdevHistogram = no;   # 'Show Bollinger Band Stdev %'

def na = Double.NaN;
def last = isNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
DefineGlobalColor("up", CreateColor(0,255,187));
DefineGlobalColor("dn", CreateColor(255,0,0));
DefineGlobalColor("histup", CreateColor(38,166,154));
DefineGlobalColor("histdn", CreateColor(178,223,219));

def upper1 = close + 0.05 * close;
def lower1 = close - 0.05 * close;
def stdL = close > lower1;
def stdS = close < upper1;

def basis = Average(Source, BollingerBandLength);
def dev   = bbMultiplier * StDev(Source, BollingerBandLength);

def upper = basis + dev;
def lower = basis - dev;
def positionBetweenBands = 100 * (Source - lower) / (upper - lower);
def hist = 100 * dev/close;

def crossUp = (positionBetweenBands Crosses above -8) and stdL;
def crossDn = (positionBetweenBands Crosses Below 108) and stdS;

def upCol = positionBetweenBands > 50;
def upCol1 = positionBetweenBands> 95;
def upCol2 = positionBetweenBands> 110;
def dnCol = positionBetweenBands <= 50;
def dnCol1 = positionBetweenBands<= 25;
def dnCol2 = positionBetweenBands<= 10;

def obupper = if last then na else pos;#if showBbStdev then 1 else pos;
def oblower = if last then na else if showBbStdevHistogram then 0.65 else 110;
def obmid = if last then na else if showBbStdevHistogram then 0.4 else 95;
def osupper = if last then na else if showBbStdevHistogram then 0.1 else 10;
def oslower = if last then na else neg;#then 0 else neg;
def osmid = if last then na else if showBbStdevHistogram then 0.25 else 25;

plot SigUp = if showBbStdevHistogram then na else if crossUp then 5 else -10;
plot SigDn = if showBbStdevHistogram then na else if crossDn then 115 else 130;
SigUp.SetLineWeight(2);
SigDn.SetLineWeight(2);
SigUp.SetDefaultColor(Color.CYAN);
SigDn.SetDefaultColor(Color.MAGENTA);

plot SqUp = if showBbStdevHistogram then if crossUp then hist+0.05 else na else na;
plot SqDn = if showBbStdevHistogram then if crossDn then hist+0.05 else na else na;
SqUp.SetLineWeight(2);
SqDn.SetLineWeight(2);
SqUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
SqDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
SqUp.SetDefaultColor(Color.GREEN);
SqDn.SetDefaultColor(Color.RED);

plot z = if showBbStdevHistogram then na else positionBetweenBands;
z.AssignValueColor(if upCol then GlobalColor("up") else GlobalColor("dn"));
z.SetLineWeight(2);

plot Histo = if showBbStdevHistogram then hist else na;
Histo.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Histo.AssignValueColor( if hist>hist[1] then GlobalColor("histup") else GlobalColor("histdn"));

plot mid = if last or showBbStdevHistogram then na else 50;
mid.SetDefaultColor(Color.GRAY);
mid.SetStyle(Curve.SHORT_DASH);

AssignPriceColor(if !colorBars then Color.CURRENT else if upCol then
                 if upCol1 then Color.GREEN else Color.DARK_GREEN else
                 if dnCol1 then Color.RED else Color.DARK_RED);

AddCloud(obupper, oblower, Color.RED);#
AddCloud(oblower, obmid, Color.DARK_RED);
AddCloud(osupper, oslower, Color.GREEN, Color.GREEN, showBbStdevHistogram);
AddCloud(osmid, osupper, Color.DARK_GREEN);

AddCloud(if upCol  then z else na, mid, Color.DARK_GREEN);
AddCloud(if upCol1 then z else na, mid, Color.DARK_GREEN);
AddCloud(if upCol2 then z else na, mid, Color.DARK_GREEN);

AddCloud(if dnCol then mid else na,  z, Color.DARK_RED);
AddCloud(if dnCol1 then mid else na, z, Color.DARK_RED);
AddCloud(if dnCol2 then mid else na, z, Color.DARK_RED);


#-- END of CODE
MTF?
 
Multi-TimeFrame (MTF) Bollinger Bands Percentile (BBPct) + STD Channels [Algo Alert]
Ruby:
# MTF Bollinger Bands Percentile (BBPct) + STD Channels [Algo Alert]
# Converted by Sam4Cok@Samer800    - 07/2023
declare lower;
#//Symmetrical Standard Deviation Channels

#//BBPCT
input agg = AggregationPeriod.TEN_MIN;
input colorBars = yes;
input BollingerBandLength = 20;    # 'Bollinger Band'
input bbMultiplier = 2.0;          # "Multiplier"
input showBbStdevHistogram = no;   # 'Show Bollinger Band Stdev %'

def Source = close(Period =agg);   # "Source"
def na = Double.NaN;
def last = isNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
DefineGlobalColor("up", CreateColor(0,255,187));
DefineGlobalColor("dn", CreateColor(255,0,0));
DefineGlobalColor("histup", CreateColor(38,166,154));
DefineGlobalColor("histdn", CreateColor(178,223,219));

def upper1 = Source + 0.05 * Source;
def lower1 = Source - 0.05 * Source;
def stdL = Source > lower1;
def stdS = Source < upper1;

def basis = Average(Source, BollingerBandLength);
def dev   = bbMultiplier * StDev(Source, BollingerBandLength);

def upper = basis + dev;
def lower = basis - dev;
def positionBetweenBands = 100 * (Source - lower) / (upper - lower);
def hist = 100 * dev/Source;

def crossUp = (positionBetweenBands Crosses above -8) and stdL;
def crossDn = (positionBetweenBands Crosses Below 108) and stdS;

def upCol = positionBetweenBands > 50;
def upCol1 = positionBetweenBands> 95;
def upCol2 = positionBetweenBands> 110;
def dnCol = positionBetweenBands <= 50;
def dnCol1 = positionBetweenBands<= 25;
def dnCol2 = positionBetweenBands<= 10;

def obupper = if last then na else pos;#if showBbStdev then 1 else pos;
def oblower = if last then na else if showBbStdevHistogram then 0.65 else 110;
def obmid = if last then na else if showBbStdevHistogram then 0.4 else 95;
def osupper = if last then na else if showBbStdevHistogram then 0.1 else 10;
def oslower = if last then na else neg;#then 0 else neg;
def osmid = if last then na else if showBbStdevHistogram then 0.25 else 25;

plot SigUp = if showBbStdevHistogram then na else if crossUp then 5 else -10;
plot SigDn = if showBbStdevHistogram then na else if crossDn then 115 else 130;
SigUp.SetLineWeight(2);
SigDn.SetLineWeight(2);
SigUp.SetDefaultColor(Color.CYAN);
SigDn.SetDefaultColor(Color.MAGENTA);

plot SqUp = if showBbStdevHistogram then if crossUp then hist+0.05 else na else na;
plot SqDn = if showBbStdevHistogram then if crossDn then hist+0.05 else na else na;
SqUp.SetLineWeight(2);
SqDn.SetLineWeight(2);
SqUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
SqDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
SqUp.SetDefaultColor(Color.GREEN);
SqDn.SetDefaultColor(Color.RED);

plot z = if showBbStdevHistogram then na else positionBetweenBands;
z.AssignValueColor(if upCol then GlobalColor("up") else GlobalColor("dn"));
z.SetLineWeight(2);

plot Histo = if showBbStdevHistogram then hist else na;
Histo.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Histo.AssignValueColor( if hist>hist[1] then GlobalColor("histup") else GlobalColor("histdn"));

plot mid = if last or showBbStdevHistogram then na else 50;
mid.SetDefaultColor(Color.GRAY);
mid.SetStyle(Curve.SHORT_DASH);

AssignPriceColor(if !colorBars then Color.CURRENT else if upCol then
                 if upCol1 then Color.GREEN else Color.DARK_GREEN else
                 if dnCol1 then Color.RED else Color.DARK_RED);

AddCloud(obupper, oblower, Color.RED);#
AddCloud(oblower, obmid, Color.DARK_RED);
AddCloud(osupper, oslower, Color.GREEN, Color.GREEN, showBbStdevHistogram);
AddCloud(osmid, osupper, Color.DARK_GREEN);

AddCloud(if upCol  then z else na, mid, Color.DARK_GREEN);
AddCloud(if upCol1 then z else na, mid, Color.DARK_GREEN);
AddCloud(if upCol2 then z else na, mid, Color.DARK_GREEN);

AddCloud(if dnCol then mid else na,  z, Color.DARK_RED);
AddCloud(if dnCol1 then mid else na, z, Color.DARK_RED);
AddCloud(if dnCol2 then mid else na, z, Color.DARK_RED);


#-- END of CODE
@Trading51
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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