Bollinger bands and Keltner bands for ThinkorSwim

arod49

New member
Does anyone know how to add a custom color cloud to fill in the Bollinger Band/Keltner Channel? thanks
 
Try this:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

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);

plot 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));

AddCloud(UpperBand, Midline, Color.Green, Color.Green);
AddCloud(LowerBand, Midline, Color.Red, Color.Red);
 
Last edited:
Anyone have/able to create something like the TradingView Bollinger Bands so that is has the cloud look to it? I found one deep on reddit but it was shaded red/green and couldn’t change the colors.
 
@BenTen The AddCloud() lines only paint the top and bottom different colors, not trending colors... I've been working on a BollingerBand indicator and haven't been able to make the cloud paint properly... I tried looking at MomentumKeltnerChannels by @Pensar but my brain just isn't in the game this evening... Banged my head earlier and must have jarred some dust loose in there... Any help would be greatly appreciated...
 
@rad14733 I believe you can only assign one color to each cloud. Is that what you were asking about?
No... MomentumKeltnerBands does trending colors, UpTrend and DownTrend... The issue is the BollingerBands and KeltnerChannels never do a crossover so the code needs to be faked out into trending...
 
Last edited by a moderator:
@rad14733 The Bollinger Bands will expand along as price continues its uptrend or downtrend, so it's definitely different from the MomentumKelterBands. With the MomentumKelterBands, the price can move far away from it in either direction.
 
hello I'm looking for candle to be painted blue if the Bollinger bands 20 period are inside of the keltner channel 20 period if anyone can help me out thank you
 
@arod49

Code:
declare upper;
declare weak_volume_dependency;

input price = close;
input bb_averageType = AverageType.Simple;
input bb_length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;

def sDev = stdev(data = price, length = bb_length);

def MidLine = MovingAverage(bb_averageType, data = price, length = bb_length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;

input kc_averageType = AverageType.Simple;
input trueRangeAverageType = AverageType.SIMPLE;
input kc_length = 20;
input factor = 1.5;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), kc_length);

def average = MovingAverage(kc_averageType, price, kc_length);
def UpperChannel = average + shift;
def LowerChannel = average - shift;

AssignPriceColor(if UpperBand < UpperChannel and LowerBand > LowerChannel then color.BLUE else color.CURRENT);
 
@generic hey man I would really appreciate it you can help me out with another code , im looking for candle to be painted yellow IF the LOW of a candle is below keltner channels and Bollinger bands LOWERBAND but CLOSES above the keltner channel/bollingerband LOWERBAND
 
@arod49 Add this to the bottom of the code. Note that this will overlap with the blue bars if it's also in a squeeze.

Code:
AssignPriceColor(if low < LowerBand and low < LowerChannel and close > LowerBand and close > LowerChannel then color.YELLOW else color.CURRENT);
 
Hi,
Can someone help me setting a background color for Bollinger Bands on TOS? Thank you.
@mts1240 Welcome to the usthinkscript forums... Which version of the Bollinger Bands are you currently using...??? If you are using the code in Post #2 above then you could use the following code if you want the entire Bollinger Band background the same color... Notice the changes to the last two lines of code in comparison the the code in Post #2... For more information on clouds, refer to AddCloud() in the Thinkscript Learning Center...

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

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);

plot 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));

AddCloud(UpperBand, LowerBand, Color.Green, Color.Green);
#AddCloud(LowerBand, Midline, Color.Red, Color.Red);
 
SEE IMPROVED VERSION HERE:
https://usethinkscript.com/threads/keltner-channel-bollinger-band-cloud.551/page-2#post-80550

friends,

my first official attempt at assembly - a crude mashing together to make a 2-in-1 BB/KC. could someone please help me to create multiple ATR bands (via the KC indicator)? for clarity, i currently have the 1st set at ATR factor 1.5 and i would like to set more bands at for instance 2 and 2.5 ATR.

please guide me if my code is suboptimal as well. much appreciated!

here it is:

Code:
# 2-in-1 BB/KC by Ronin

# BB Indicator
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);

plot 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(1));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(1));

# KC Indicator
input KCdisplace = 0;
input factor = 1.5;
input KClength = 20;
input KCprice = close;
input KCaverageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);

def average = MovingAverage(averageType, price, length);

plot Avg = average[-displace];
Avg.SetDefaultColor(GetColor(1));

plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(5));

plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));
 
Last edited by a moderator:
my first official attempt at assembly - a crude mashing together to make a 2-in-1 BB/KC. could someone please help me to create multiple ATR bands (via the KC indicator)? for clarity, i currently have the 1st set at ATR factor 1.5 and i would like to set more bands at for instance 2 and 2.5 ATR.

If you don't need all those inputs to fiddle with the settings without touching code you can simplify as follows. You can also use SetDefaultColor, SetStyle, SetLineWeight and/or SetPaintingStrategy to have the default colors and line styles as you want.

Ruby:
plot bbu = reference BollingerBands().UpperBand;
plot bbm = reference BollingerBands().MidLine;
plot bbl = reference BollingerBands().LowerBand;

plot kc15u = reference KeltnerChannels(factor = 1.5).Upper_Band;
plot kc15l = reference KeltnerChannels(factor = 1.5).Lower_Band;

plot kc20u = reference KeltnerChannels(factor = 2.0.Upper_Band;
plot kc20l = reference KeltnerChannels(factor = 2.0.Lower_Band;

plot kc25u = reference KeltnerChannels(factor = 2.5).Upper_Band;
plot kc25l = reference KeltnerChannels(factor = 2.5).Lower_Band;
 

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
528 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