Colored candles based on Bollinger Bands?

A

arod49

New member
Can someone make blue colored candles when price is higher than the upper Bollinger Band? thanks
 
T

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

tradeking313

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

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

tradeking313

Member
@mc01439 im working on it now but its not giving me the actual correct price for the bollinger bands regardless of the current price
 
T

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
 
T

tradeking313

Member
@tomsk you are a god!!!!!!!!!!!!!!! thanks so muchhhhhhhhhh
 
I

inhouselr

New member
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?
 
C

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.
 

Similar threads

Top