Colored candles based on Bollinger Bands?

tomsk

Well-known member
VIP
@arod49 Per your request here is the COMPLETED code to color candles BLUE if they close above the Bollinger Upper band

Code:
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;

AssignPriceColor(if close > UpperBand then Color.BLUE else Color.CURRENT);
 

mc01439

Well-known member
2019 Donor
VIP
You should be able to take this code and change it to what you are looking for. Any help needed let me know.


Code:
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;

#UpperBand
def UBbu = close > UpperBand;
def UBbd = close < UpperBand and close > MidLine;

AddLabel(UBbu, " Price Above UpperBand @ " + close, Color.DARK_GREEN);
AddLabel(UBbd, " Price Below UpperBand @ " + close, Color.DARK_RED);

#LowerBand
def LBbu = close < LowerBand;
def LBbd = close > LowerBand and close < MidLine;

AddLabel(LBbu, " Price Below LowerBand @ " + close, Color.RED);
AddLabel(LBbd, " Price Above UpperBand @ " + close, Color.GREEN);
 

tomsk

Well-known member
VIP
@tomsk is there any way we can have a chart label for each bollinger band...lower, mid, and upper band?? thanks...you are awesome!!!!!!!!!!!

@tradeking313 Didn't quite realize there is a bit of interest in the Bollinger Band. I took another look at it and made it visually more distinctive, and added alarms as well when it goes outside the band. Here then is version 1.1 if the study

Code:
# Bollinger Band with High Low Colored
# tomsk
# 12.14.2019

# V1.0 - 12.11.2019 - tomsk - Standard TOS BB tagged with BLUE candles when close above the upper band
# V1.1 - 12.14.2019 - tomsk - Adjustments to make display visually more distinctive and added alarms

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;

MidLine.SetDefaultColor(Color.Yellow);
LowerBand.SetDefaultColor(Color.Cyan);
UpperBand.SetDefaultColor(Color.Green);

AssignPriceColor(if close > UpperBand then Color.Lime else if close < LowerBand then Color.Magenta else Color.Gray);

Alert(close crosses above UpperBand, "BB cross above Upper", Alert.BAR, Sound.Ring);
Alert(close crosses below LowerBand, "BB cross below Lower", Alert.BAR, Sound.Bell);
# End Bollinger Band
 

C4men

Member
I have what I think is a simple request, but not sure where to start. I want to easily display the variance (%) between the outer and mid Bollinger Bands.
So if the upper band is 10% away from the mid-line (point-in-time), I'd like to create a label that looks something like this:

[-5 Bar BB% = 10%]

-5 would be the number of bars ago; I'd want to be able to adjust this in the input settings to whatever X bars ago I choose
10% would be calculated; the percent difference between the outer bollinger band and the mid-line (i.e. there's a 10% variance)

So essentially, look at the Bollinger Bands at a given point in time, calculate the variance, put it on the label.

Is this possible? Really hopeful someone can help me here, because it would also really help a custom scan I am developing.
 

holdenxsmith

New member
VIP
I love the lime candle for upper band and magenta color for the lower band but how do I keep the other colors of the candles its default colors (red/green) instead of gray?
This code will keep your default red/green if it is not upper or lower band.

Code:
# Bollinger Band with High Low Colored
# tomsk
# 12.14.2019

# V1.0 - 12.11.2019 - tomsk - Standard TOS BB tagged with BLUE candles when close above the upper band
# V1.1 - 12.14.2019 - tomsk - Adjustments to make display visually more distinctive and added alarms

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;

MidLine.SetDefaultColor(Color.YELLOW);
LowerBand.SetDefaultColor(Color.CYAN);
UpperBand.SetDefaultColor(Color.GREEN);

AssignPriceColor(if close > UpperBand then Color.LIME else if close < LowerBand then Color.MAGENTA else color.CURRENT);

Alert(close crosses above UpperBand, "BB cross above Upper", Alert.BAR, Sound.Ring);
Alert(close crosses below LowerBand, "BB cross below Lower", Alert.BAR, Sound.Bell);
# End Bollinger Band
 

C-Note Johnson

New member
I'm almost certain it must be on useThinkScript somewhere. I am looking for a simple Bollinger band to put on my price chart that will change colors in a period of price expansion, price contraction, or a period of price doing relatively nothing. Please drop me a line. Thank you, C-Note Johnson
 

rad14733

Well-known member
VIP
I'm almost certain it must be on useThinkScript somewhere. I am looking for a simple Bollinger band to put on my price chart that will change colors in a period of price expansion, price contraction, or a period of price doing relatively nothing. Please drop me a line. Thank you, C-Note Johnson
You, essentially, want rainbow or trend indicating Bollinger Bands which is nothing more than three trend indicating bands...
 

C-Note Johnson

New member
You, essentially, want rainbow or trend indicating Bollinger Bands which is nothing more than three trend indicating bands...
Hello rad14733, I am looking for Bollinger bands much like the ones included in the " Bollinger bands with MACD ". This was an indicator that I got from Horserider. It is exactly what I need. Thank you, C-Note Johnson
 

C-Note Johnson

New member
Thanks rad14733, I need Bollinger bands on the top and bottom. So two lines total. Check out " Bollinger bands with MACD " from horserider. I currently use that indicator every day. Thanks again. C-Note Richards.
 

rad14733

Well-known member
VIP
Have you tried dragging a copy of that lower indicator into the upper indicator section by chance...???

I had to hunt around because that indicator is actually horseriders Ultimate MACD...
 

Similar threads

Top