#
# 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);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
You are amazing! Thank you!!@army11b1980 Sure, code above has been updated.
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...@rad14733 I believe you can only assign one color to each cloud. Is that what you were asking about?
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);
@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...Hi,
Can someone help me setting a background color for Bollinger Bands on TOS? Thank you.
#
# 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);
# 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));
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.
SetDefaultColor
, SetStyle
, SetLineWeight
and/or SetPaintingStrategy
to have the default colors and line styles as you want.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;
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
J | Gap between Keltner Channels/Bollinger Bands in scanner | Questions | 8 | |
M | Price crosses Bollinger Bands | Questions | 2 | |
F | Bollinger Bands Strategy | Questions | 2 | |
D | Verify Larry McMillan’s Modified Bollinger Bands | Questions | 6 | |
B | Daily Bollinger Bands | Questions | 10 |
Start a new thread and receive assistance from our community.
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.
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.