Measure the distance between Price and upper Bollinger Bands

I was wondering if someone could apply the same logic from this thread. How can I measure the distance from the upper bollinger band and plot that value as % in a watchlist column?

I would be forever grateful to the person who has the skill to update my code to show % distance from the upper bollinger band.

Hoping someone can assist.

Thank you whoever you may be.

Code:
input price = close;

input displace = 0;

input length = 10;

input Num_Dev_Dn = -1.5;

input Num_Dev_up = 1.5;

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;

plot UpperBand = MidLine + num_Dev_Up * sDev;

def aboveUpperBand = close > UpperBand;

def almostToUpperBand = close < UpperBand and close > UpperBand;



UpperBand.AssignValueColor(if aboveUpperBand or almostToUpperBand then Color.BLACK else Color.WHITE);

AssignBackgroundColor(if aboveUpperBand then Color.GREEN else if almostToUpperBand then Color.YELLOW else Color.BLACK);
 
Solution
I figured it out. Wasn't too bad. Posted here if someone could use this.

Cheers!

Code:
input price = OPEN;
input displace = 0;
input length = 10;
input Num_Dev_Dn = -1.5;
input Num_Dev_up = 1.5;
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;
plot calc = ((price - UpperBand)/ UpperBand * 100);
def aboveUpperBand = OPEN > UpperBand;
def almostToUpperBand = OPEN < UpperBand and OPEN > UpperBand ;
I figured it out. Wasn't too bad. Posted here if someone could use this.

Cheers!

Code:
input price = OPEN;
input displace = 0;
input length = 10;
input Num_Dev_Dn = -1.5;
input Num_Dev_up = 1.5;
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;
plot calc = ((price - UpperBand)/ UpperBand * 100);
def aboveUpperBand = OPEN > UpperBand;
def almostToUpperBand = OPEN < UpperBand and OPEN > UpperBand ;
 
Solution

vvasanthr

New member
VIP
I figured it out. Wasn't too bad. Posted here if someone could use this.

Cheers!

Code:
input price = OPEN;
input displace = 0;
input length = 10;
input Num_Dev_Dn = -1.5;
input Num_Dev_up = 1.5;
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;
plot calc = ((price - UpperBand)/ UpperBand * 100);
def aboveUpperBand = OPEN > UpperBand;
def almostToUpperBand = OPEN < UpperBand and OPEN > UpperBand ;
@perseverance_trading1-Can you explain little more about how you are using this code? are you creating as a study & then creating a watchlist ?
If you can share some screenshot will be helpful
 

XeoNoX

Well-known member
VIP
I am looking for how far price gets above the upper bollinger band
you stated you figured it out in your earlier post... are you trying to scan for something different? can you give more detail? can you give example of what you mean? how far in what increment? and upper band compared to the price or the price compared to the upper band?
 
you stated you figured it out in your earlier post... are you trying to scan for something different? can you give more detail? can you give example of what you mean? how far in what increment? and upper band compared to the price or the price compared to the upper band?
@XeoNoX That is correct. In terms of price, how far price gets above the upper band in terms of %. It is based on the current price and current band.
 

XeoNoX

Well-known member
VIP
@perseverance_trading1
here is what you requested.
The % that closing Price is away from the UpperBand BollingerBand as a Label
Code:
# The % that closing Price is away from the UpperBand BollingerBand as a Label
# By XeoNoX Via usethinkscript.com
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));
def percent_away = (close- UpperBand) / close;
AddLabel (yes, "Percent Price Away from Upper Band BollingerBand: " + AsPercent(percent_away), if percent_away >= .001 then color.dark_green else if percent_away <= .001 then color.downTICK else color.gray);
 

Similar threads

Top