Keltner channel/ Bollinger Band Cloud

arod49

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

BenTen

Administrative
Staff member
Staff
VIP
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:

Liquidity

New member
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.
 

rad14733

Well-known member
VIP
@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

Well-known member
VIP
@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:

BenTen

Administrative
Staff member
Staff
VIP
@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.
 

rad14733

Well-known member
VIP
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);
 

Ronin13

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

Slippage

Well-known member
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;
 

George_Z

New member
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);
This is epic, was curious if there was a way to change the colors of the clouds?
 

mbarcala

New member
I create two Deviation in my case (2.0, -2.0 and 3.0, -3.0) and I add some cloud in between them, I did add some opacity in the cloud too but in reality the cloud doesn't get transparent at all.

Code:
input Opacity = 50;

input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;

input Num_Dev_Dn2 = -3.0;
input Num_Dev_up2 = 3.0;

AddCloud(UpperBand, UpperBand2, Color.Green, Color.Green, Opacity);
AddCloud(LowerBand, LowerBand2, Color.Red, Color.Red, Opacity);

I'm doing something wrong? can this cloud be more transparent if I want?

help please?
 

Similar threads

Top