# Can anyone code plot for measuring percentage on a chart?

#### DSG

##### New member
I am always using my measuring tool to measure the high and low of the recent price action since the scale on the chart adjusts to the price of the entire chart. I was wondering if there was a way to plot a vertical bar to the right of the most current bar that would simply show me what 4% from high to low of that reference bar would look like so I can simply run through my charts and know right away if the price action above and below the last close is above or below a certain percentage, ie, 4% or 5%? Is that possible in TOS? Thanks so much!!

Solution
Thank you so much for the reply! The best analogy I can think of is when you look at a map, there is always a bar on the map that says, 1 inch = X miles. I'm looking for the same exact type of scale as a reference on my chart. I would ideally want a vertical line drawn to the right of recent price action that is a fixed percentage tall so what when I look at the chart, I can instantly see the scale I'm looking at. Another example would be that if I'm looking at a ticker and the price scale on the right side goes from 30 to 40 and the current price is \$35/share, then if I'm using 4% from the earlier discussion, it would plot a vertical line that would be \$1.40 dollars tall. And if the right scale only goes from 30 to 40, then...

#### halcyonguy

##### Well-known member
VIP
I am always using my measuring tool to measure the high and low of the recent price action since the scale on the chart adjusts to the price of the entire chart. I was wondering if there was a way to plot a vertical bar to the right of the most current bar that would simply show me what 4% from high to low of that reference bar would look like so I can simply run through my charts and know right away if the price action above and below the last close is above or below a certain percentage, ie, 4% or 5%? Is that possible in TOS? Thanks so much!!

I have something similar that I could modify but,
I don't understand what you want a percentage of.
'Recent price action' is too vague.

Do you mean, you want something that is slightly taller than the previous bar, when the current bar is the last bar?

(using words for now, not offsets. not worried about accurate code yet, just trying to understand the process)

find the height of the previous bar,
y=high-low

find 4% of y
yper = y * 0.04

add the % number to the previous high and subtract it from the previous low.

#### DSG

##### New member
I have something similar that I could modify but,
I don't understand what you want a percentage of.
'Recent price action' is too vague.

Do you mean, you want something that is slightly taller than the previous bar, when the current bar is the last bar?

(using words for now, not offsets. not worried about accurate code yet, just trying to understand the process)

find the height of the previous bar,
y=high-low

find 4% of y
yper = y * 0.04

add the % number to the previous high and subtract it from the previous low.
Thank you so much for the reply! The best analogy I can think of is when you look at a map, there is always a bar on the map that says, 1 inch = X miles. I'm looking for the same exact type of scale as a reference on my chart. I would ideally want a vertical line drawn to the right of recent price action that is a fixed percentage tall so what when I look at the chart, I can instantly see the scale I'm looking at. Another example would be that if I'm looking at a ticker and the price scale on the right side goes from 30 to 40 and the current price is \$35/share, then if I'm using 4% from the earlier discussion, it would plot a vertical line that would be \$1.40 dollars tall. And if the right scale only goes from 30 to 40, then that \$1.40 would produce a vertical line for my reference that would be let's say 1 inch tall on my screen. That would tell me a lot when looking at the chart. Now if we contrast that with a ticker I'm looking at where the price scale is from 30 to 50 which is double the 30-40 example. Then if price was still at \$35/share, the same \$1.40 would produce a vertical line that would be 0.5 inch tall on my screen.

#### JoeDV

##### Member
Thank you so much for the reply! The best analogy I can think of is when you look at a map, there is always a bar on the map that says, 1 inch = X miles. I'm looking for the same exact type of scale as a reference on my chart. ...

I take it you're using a log scale for your charts then as well. I personally believe it should be the default. A move from 30 to 40 (33%) should not be on the same scale as 40-50 (25%).

#### halcyonguy

##### Well-known member
VIP
Thank you so much for the reply! The best analogy I can think of is when you look at a map, there is always a bar on the map that says, 1 inch = X miles. I'm looking for the same exact type of scale as a reference on my chart. I would ideally want a vertical line drawn to the right of recent price action that is a fixed percentage tall so what when I look at the chart, I can instantly see the scale I'm looking at. Another example would be that if I'm looking at a ticker and the price scale on the right side goes from 30 to 40 and the current price is \$35/share, then if I'm using 4% from the earlier discussion, it would plot a vertical line that would be \$1.40 dollars tall. And if the right scale only goes from 30 to 40, then that \$1.40 would produce a vertical line for my reference that would be let's say 1 inch tall on my screen. That would tell me a lot when looking at the chart. Now if we contrast that with a ticker I'm looking at where the price scale is from 30 to 50 which is double the 30-40 example. Then if price was still at \$35/share, the same \$1.40 would produce a vertical line that would be 0.5 inch tall on my screen.

after reading all of that a few times, and trying a couple of formulas, i figured out what you want.
all you had to say was,

column height = (price / (highest - lowest )) * %

i will modify my study and post it in a bit.

i didn't ask for analogies or examples or how many inches this might appear to be on the screen. all of those things are irrelevant.
but, everyone interprets data differently. and you did manage to describe the numbers.
why am i rambling on about your post? so that in future questions, you and others, will think about the places on a chart that define the conditions.

• MerryDay

#### halcyonguy

##### Well-known member
VIP
Thank you so much for the reply! The best analogy I can think of is when you look at a map, there is always a bar on the map that says, 1 inch = X miles. I'm looking for the same exact type of scale as a reference on my chart. I would ideally want a vertical line drawn to the right of recent price action that is a fixed percentage tall so what when I look at the chart, I can instantly see the scale I'm looking at. Another example would be that if I'm looking at a ticker and the price scale on the right side goes from 30 to 40 and the current price is \$35/share, then if I'm using 4% from the earlier discussion, it would plot a vertical line that would be \$1.40 dollars tall. And if the right scale only goes from 30 to 40, then that \$1.40 would produce a vertical line for my reference that would be let's say 1 inch tall on my screen. That would tell me a lot when looking at the chart. Now if we contrast that with a ticker I'm looking at where the price scale is from 30 to 50 which is double the 30-40 example. Then if price was still at \$35/share, the same \$1.40 would produce a vertical line that would be 0.5 inch tall on my screen.

took a little longer to alter/hack my other column study (and other stuff came up)

this draws a column, 2 bars wide, after the last bar, that has a height based on this formula,
. column height = (price / (highest - lowest )) * %

the column is vertically centered on the current close price

options,
. pick a %
. show some labels
.....highest, lowest price, and the price range
.....% number, column price range
. column offset ( -5) . referenced from the right side of column. can move the column sideways anywhere, x bars from the last bar
. show price bubbles next to the column

Ruby:
``````# ref_column_percent_hilo0e

#---------------------------------
# halcyonguy
# 22-02-22
# draw a colored vertical column,
#  to act as a visual reference to a price range.
#  column height = (price / (highest - lowest )) * %
# ---------------------

def bn = BarNumber();
def na = Double.NaN;
def cls = close;
# ------------------------------------
# Line At Price , Mobius
# Alternative to using the HighestAll() function
def barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
then close
else c;
def clsline = if IsNaN(close[-barsBack])
then c[-barsBack]
else Double.NaN;
# ------------------------------------

#def lastbar = (!IsNaN(cls) and IsNaN(cls[-1]));

#----------------------------------

# column height = (price / (highest - lowest )) * %

input ht_percent = 4.0;
def hi = highestall(high);
def lo = lowestall(low);
def column_rng_ht = round((clsline / (hi - lo )) * (ht_percent/100),2);

input show_hilo_labels = yes;
addlabel(show_hilo_labels, hi + " highest", color.yellow);
addlabel(show_hilo_labels, lo + " lowest", color.yellow);
addlabel(show_hilo_labels, (hi - lo) + " price range", color.yellow);

input show_column_ht_label = yes;
addlabel(show_column_ht_label, ht_percent + " %", color.magenta);
addlabel(show_column_ht_label, column_rng_ht + " column height", color.magenta);

# -----------------------------------

input column_offset_from_lastbar = -5;
#hint column_offset_from_lastbar: Quantity of bars to shift the right edge of the column, away from the last bar. - to the right, + to the left.

#def bb = bars_offset;
def coloff = column_offset_from_lastbar;

# bar of right edge of column
def x = (!IsNaN(cls[-coloff]) and IsNaN(cls[-(coloff + 1)]) );
# -----------------------------------

def upper2 = Round(clsline + (column_rng_ht/2), 2);
def lower2 = Round(clsline - (column_rng_ht/2), 2);

def lastbaroff = x;
def barbb = if lastbaroff  then 1 else 0;
def linebars = (lastbaroff or lastbaroff[-1] or lastbaroff[-2]);

# top and bottom, horz cloud levels
def up2b = if lastbaroff then upper2 else if lastbaroff[-1] then upper2[-1]  else if lastbaroff[-2] then upper2[-2] else na;
def low2b = if lastbaroff then lower2 else if lastbaroff[-1] then lower2[-1]  else if lastbaroff[-2] then lower2[-2] else na;

input price_bubbles = no;
def spb = price_bubbles;

def price_bubble_offset = 0;
#hint price_bubble_offset: Quantity of bars to shift the bubbles from the right edge of the column. - to the right, + to the left.
def po = price_bubble_offset;

# price bubbles
AddChartBubble(spb[-po] and barbb[-po], up2b[-po], up2b[-po], Color.CYAN, yes);
AddChartBubble(spb[-po] and barbb[-po], low2b[-po], low2b[-po], Color.CYAN, no);

# plot lines, to get price bubbles to appear on axis
plot z1 = up2b;
z1.setdefaultcolor(color.cyan);
plot z2 = low2b;
z2.setdefaultcolor(color.cyan);
#``````

PM 20Day 15min #### DSG

##### New member
took a little longer to alter/hack my other column study (and other stuff came up)

this draws a column, 2 bars wide, after the last bar, that has a height based on this formula,
. column height = (price / (highest - lowest )) * %

the column is vertically centered on the current close price

options,
. pick a %
. show some labels
.....highest, lowest price, and the price range
.....% number, column price range
. column offset ( -5) . referenced from the right side of column. can move the column sideways anywhere, x bars from the last bar
. show price bubbles next to the column

Ruby:
``````# ref_column_percent_hilo0e

#---------------------------------
# halcyonguy
# 22-02-22
# draw a colored vertical column,
#  to act as a visual reference to a price range.
#  column height = (price / (highest - lowest )) * %
# ---------------------

def bn = BarNumber();
def na = Double.NaN;
def cls = close;
# ------------------------------------
# Line At Price , Mobius
# Alternative to using the HighestAll() function
def barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
then close
else c;
def clsline = if IsNaN(close[-barsBack])
then c[-barsBack]
else Double.NaN;
# ------------------------------------

#def lastbar = (!IsNaN(cls) and IsNaN(cls[-1]));

#----------------------------------

# column height = (price / (highest - lowest )) * %

input ht_percent = 4.0;
def hi = highestall(high);
def lo = lowestall(low);
def column_rng_ht = round((clsline / (hi - lo )) * (ht_percent/100),2);

input show_hilo_labels = yes;
addlabel(show_hilo_labels, hi + " highest", color.yellow);
addlabel(show_hilo_labels, lo + " lowest", color.yellow);
addlabel(show_hilo_labels, (hi - lo) + " price range", color.yellow);

input show_column_ht_label = yes;
addlabel(show_column_ht_label, ht_percent + " %", color.magenta);
addlabel(show_column_ht_label, column_rng_ht + " column height", color.magenta);

# -----------------------------------

input column_offset_from_lastbar = -5;
#hint column_offset_from_lastbar: Quantity of bars to shift the right edge of the column, away from the last bar. - to the right, + to the left.

#def bb = bars_offset;
def coloff = column_offset_from_lastbar;

# bar of right edge of column
def x = (!IsNaN(cls[-coloff]) and IsNaN(cls[-(coloff + 1)]) );
# -----------------------------------

def upper2 = Round(clsline + (column_rng_ht/2), 2);
def lower2 = Round(clsline - (column_rng_ht/2), 2);

def lastbaroff = x;
def barbb = if lastbaroff  then 1 else 0;
def linebars = (lastbaroff or lastbaroff[-1] or lastbaroff[-2]);

# top and bottom, horz cloud levels
def up2b = if lastbaroff then upper2 else if lastbaroff[-1] then upper2[-1]  else if lastbaroff[-2] then upper2[-2] else na;
def low2b = if lastbaroff then lower2 else if lastbaroff[-1] then lower2[-1]  else if lastbaroff[-2] then lower2[-2] else na;

input price_bubbles = no;
def spb = price_bubbles;

def price_bubble_offset = 0;
#hint price_bubble_offset: Quantity of bars to shift the bubbles from the right edge of the column. - to the right, + to the left.
def po = price_bubble_offset;

# price bubbles
AddChartBubble(spb[-po] and barbb[-po], up2b[-po], up2b[-po], Color.CYAN, yes);
AddChartBubble(spb[-po] and barbb[-po], low2b[-po], low2b[-po], Color.CYAN, no);

# plot lines, to get price bubbles to appear on axis
plot z1 = up2b;
z1.setdefaultcolor(color.cyan);
plot z2 = low2b;
z2.setdefaultcolor(color.cyan);
#``````

PM 20Day 15min I loaded the code and I've been trying to figure out why I'm only getting what appears like a solid cyan line. I think the way I described what I'm looking for wasn't a great way to describe it because using the highest/lowest all or I even see you already thought of the "number of bars back", however, I still think that will distort the outcome. This may be much simpler than how I described it so I'll try to explain it this way. Let's not be concerned with the highest/lowest or bars back. I think what will have this work is to simply take the closing price of the last bar and take the close and go down 4%. Then instead of having the cyan bar be above and below the close, can we have it so the top of the cyan bar is the close and then it goes down 4%?

#### halcyonguy

##### Well-known member
VIP
I loaded the code and I've been trying to figure out why I'm only getting what appears like a solid cyan line. I think the way I described what I'm looking for wasn't a great way to describe it because using the highest/lowest all or I even see you already thought of the "number of bars back", however, I still think that will distort the outcome. This may be much simpler than how I described it so I'll try to explain it this way. Let's not be concerned with the highest/lowest or bars back. I think what will have this work is to simply take the closing price of the last bar and take the close and go down 4%. Then instead of having the cyan bar be above and below the close, can we have it so the top of the cyan bar is the close and then it goes down 4%?

let's just say i am completely confused by your requests and tried to make good guesses.
in all your posts, you haven't clearly explained what data to use.

i created a verical bar to the right of the last bar, because that is what you asked for.
'..was a way to plot a vertical bar to the right of the most current bar..'
from your example numbers, i came up with this formula.
it has a height of 4% , column height = (current close / (highest - lowest )) * %

i guessed at the highestall, lowestall, because of your example of 30 to 40 in post3, and thought you meant the extreme range of prices on a chart.

the barsback variable has nothing to do with collecting data for your outputs. it is used to calculate a horizontal price level of the last bar close.
column offset.. is for locating the column, x bars from the last bar.

you still haven't defined what you want 4% of. 4% of close is a big number.

sometimes when people ask questions about things they don't understand, it's hard to put the right words together. this is where you are at.
keep trying, keep asking , explaining, don't give up. everyone was a beginner at one time and had trouble coming up with the appropriate statements. we will get it figured out.

------------------------------------

i hope this is close, or at least sparks new questions/statements to guide us.

next version, 0f
. able to shift the cyan column vertically, by entering a % number, that decides what % of the column is higher than the close.
input percent_of_column_above_last_close = 0;
. 0 will move the column down so the top is even with close. ( 0% is above close)
. 50 will center the column, half above close price, half below.

. add a variable, to pick what the 4 % is, original formula or of close.
. input column_height_type = { default percent_of_hilo_range , percent_of_close };

Ruby:
``````# ref_column_percent_hilo0f

#. shift the cyan column down, so its top is at the same price level as current close.
#. add a column on right edge of the chart, to represent the range between the highest price on the chart and the lowest.

# next ver , for DSG , % of a ht
# column height = (price / (highest - lowest )) * %
#---------------------------------
# halcyonguy
# 22-02-22
# draw a colored vertical column,
#  to act as a visual reference to a price range.
# ---------------------

def bn = BarNumber();
def na = Double.NaN;
def cls = close;
# ------------------------------------
# Line At Price , Mobius
# Alternative to using the HighestAll() function
def barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
then close
else c;
def clsline = if IsNaN(close[-barsBack])
then c[-barsBack]
else Double.NaN;
# ------------------------------------

#def lastbar = (!IsNaN(cls) and IsNaN(cls[-1]));

#----------------------------------

input ht_percent = 4.0;
def hi = highestall(high);
def lo = lowestall(low);

# orig formula
# column height = (price / (highest - lowest )) * %
#def column_rng_ht = round((clsline / (hi - lo )) * (ht_percent/100),2);

#-----------------------------------------

# choose % number type
input column_height_type = { default percent_of_hilo_range  , percent_of_close };

def ht1;
def httype;
switch (column_height_type) {
case percent_of_hilo_range:
ht1 = round((clsline / (hi - lo )) * (ht_percent/100),2);
httype = 1;
case percent_of_close:
ht1 = round((clsline * (ht_percent/100)),2);
httype = 2;
}

def  column_rng_ht = ht1;

#-----------------------------------------

input show_hilo_labels = yes;
addlabel(show_hilo_labels, hi + " highest", color.yellow);
addlabel(show_hilo_labels, lo + " lowest", color.yellow);
addlabel(show_hilo_labels, (hi - lo) + " price range", color.yellow);

input show_column_ht_label = yes;
addlabel(show_column_ht_label, ht_percent + " %", color.magenta);
addlabel(show_column_ht_label, column_rng_ht + " column height", color.magenta);

# -----------------------------------

input column_offset_from_lastbar = -5;
#hint column_offset_from_lastbar: Quantity of bars to shift the right edge of the column, away from the last bar. - to the right, + to the left.

#def bb = bars_offset;
def coloff = column_offset_from_lastbar;

# bar of right edge of column
def x = (!IsNaN(cls[-coloff]) and IsNaN(cls[-(coloff + 1)]) );
# -----------------------------------

# vertailly adjust the column, in relation to the last close
# 50 = the middle of column is lined up with close
# 0  = all of column is below the close price.
# 80 = 80% of the column height is above the close price.
input percent_of_column_above_last_close = 0;
#hint percent_of_column_above_last_close: a % number, 0 to 100, that vertically adjusts the column, in relation to the last close. \n... 50 = the middle of column is lined up with close \n ...  0  = all of column is below the close price. \n... 80 = 80% of the column height is above the close price.

def colvper2 = if percent_of_column_above_last_close < 0 then 0 else if percent_of_column_above_last_close > 100 then 100 else percent_of_column_above_last_close;
def colvper =  colvper2/100;

def coltop = (colvper * column_rng_ht);
def colbot = ( (1 - colvper) * column_rng_ht);

def upper2 = Round(clsline + coltop, 2);
def lower2 = Round(clsline - colbot, 2);

colvper + " %\n" +
ht1 + " ht\n" +
coltop + " top\n" +
colbot + " bot\n" +
upper2 + " upr\n" +
lower2 + " lwr"
, color.yellow, no);

# -----------------------------
#def upper2 = Round(clsline + (column_rng_ht/2), 2);
#def lower2 = Round(clsline - (column_rng_ht/2), 2);

# ------------------------------------
def lastbaroff = x;
def barbb = if lastbaroff  then 1 else 0;
def linebars = (lastbaroff or lastbaroff[-1] or lastbaroff[-2]);

# top and bottom, horz cloud levels
def up2b = if lastbaroff then upper2 else if lastbaroff[-1] then upper2[-1]  else if lastbaroff[-2] then upper2[-2] else na;
def low2b = if lastbaroff then lower2 else if lastbaroff[-1] then lower2[-1]  else if lastbaroff[-2] then lower2[-2] else na;

input price_bubbles = no;
def spb = price_bubbles;

def price_bubble_offset = 0;
#hint price_bubble_offset: Quantity of bars to shift the bubbles from the right edge of the column. - to the right, + to the left.
def po = price_bubble_offset;

# price bubbles
AddChartBubble(spb[-po] and barbb[-po], up2b[-po], up2b[-po], Color.CYAN, yes);
AddChartBubble(spb[-po] and barbb[-po], low2b[-po], low2b[-po], Color.CYAN, no);

# plot lines, to get price bubbles to appear on axis
plot z1 = up2b;
z1.setdefaultcolor(color.cyan);
plot z2 = low2b;
z2.setdefaultcolor(color.cyan);
#
#``````

#### DSG

##### New member
let's just say i am completely confused by your requests and tried to make good guesses.
in all your posts, you haven't clearly explained what data to use.

i created a verical bar to the right of the last bar, because that is what you asked for.
'..was a way to plot a vertical bar to the right of the most current bar..'
from your example numbers, i came up with this formula.
it has a height of 4% , column height = (current close / (highest - lowest )) * %

i guessed at the highestall, lowestall, because of your example of 30 to 40 in post3, and thought you meant the extreme range of prices on a chart.

the barsback variable has nothing to do with collecting data for your outputs. it is used to calculate a horizontal price level of the last bar close.
column offset.. is for locating the column, x bars from the last bar.

you still haven't defined what you want 4% of. 4% of close is a big number.

sometimes when people ask questions about things they don't understand, it's hard to put the right words together. this is where you are at.
keep trying, keep asking , explaining, don't give up. everyone was a beginner at one time and had trouble coming up with the appropriate statements. we will get it figured out.

------------------------------------

i hope this is close, or at least sparks new questions/statements to guide us.

next version, 0f
. able to shift the cyan column vertically, by entering a % number, that decides what % of the column is higher than the close.
input percent_of_column_above_last_close = 0;
. 0 will move the column down so the top is even with close. ( 0% is above close)
. 50 will center the column, half above close price, half below.

. add a variable, to pick what the 4 % is, original formula or of close.
. input column_height_type = { default percent_of_hilo_range , percent_of_close };

Ruby:
``````# ref_column_percent_hilo0f

#. shift the cyan column down, so its top is at the same price level as current close.
#. add a column on right edge of the chart, to represent the range between the highest price on the chart and the lowest.

# next ver , for DSG , % of a ht
# column height = (price / (highest - lowest )) * %
#---------------------------------
# halcyonguy
# 22-02-22
# draw a colored vertical column,
#  to act as a visual reference to a price range.
# ---------------------

def bn = BarNumber();
def na = Double.NaN;
def cls = close;
# ------------------------------------
# Line At Price , Mobius
# Alternative to using the HighestAll() function
def barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
then close
else c;
def clsline = if IsNaN(close[-barsBack])
then c[-barsBack]
else Double.NaN;
# ------------------------------------

#def lastbar = (!IsNaN(cls) and IsNaN(cls[-1]));

#----------------------------------

input ht_percent = 4.0;
def hi = highestall(high);
def lo = lowestall(low);

# orig formula
# column height = (price / (highest - lowest )) * %
#def column_rng_ht = round((clsline / (hi - lo )) * (ht_percent/100),2);

#-----------------------------------------

# choose % number type
input column_height_type = { default percent_of_hilo_range  , percent_of_close };

def ht1;
def httype;
switch (column_height_type) {
case percent_of_hilo_range:
ht1 = round((clsline / (hi - lo )) * (ht_percent/100),2);
httype = 1;
case percent_of_close:
ht1 = round((clsline * (ht_percent/100)),2);
httype = 2;
}

def  column_rng_ht = ht1;

#-----------------------------------------

input show_hilo_labels = yes;
addlabel(show_hilo_labels, hi + " highest", color.yellow);
addlabel(show_hilo_labels, lo + " lowest", color.yellow);
addlabel(show_hilo_labels, (hi - lo) + " price range", color.yellow);

input show_column_ht_label = yes;
addlabel(show_column_ht_label, ht_percent + " %", color.magenta);
addlabel(show_column_ht_label, column_rng_ht + " column height", color.magenta);

# -----------------------------------

input column_offset_from_lastbar = -5;
#hint column_offset_from_lastbar: Quantity of bars to shift the right edge of the column, away from the last bar. - to the right, + to the left.

#def bb = bars_offset;
def coloff = column_offset_from_lastbar;

# bar of right edge of column
def x = (!IsNaN(cls[-coloff]) and IsNaN(cls[-(coloff + 1)]) );
# -----------------------------------

# vertailly adjust the column, in relation to the last close
# 50 = the middle of column is lined up with close
# 0  = all of column is below the close price.
# 80 = 80% of the column height is above the close price.
input percent_of_column_above_last_close = 0;
#hint percent_of_column_above_last_close: a % number, 0 to 100, that vertically adjusts the column, in relation to the last close. \n... 50 = the middle of column is lined up with close \n ...  0  = all of column is below the close price. \n... 80 = 80% of the column height is above the close price.

def colvper2 = if percent_of_column_above_last_close < 0 then 0 else if percent_of_column_above_last_close > 100 then 100 else percent_of_column_above_last_close;
def colvper =  colvper2/100;

def coltop = (colvper * column_rng_ht);
def colbot = ( (1 - colvper) * column_rng_ht);

def upper2 = Round(clsline + coltop, 2);
def lower2 = Round(clsline - colbot, 2);

colvper + " %\n" +
ht1 + " ht\n" +
coltop + " top\n" +
colbot + " bot\n" +
upper2 + " upr\n" +
lower2 + " lwr"
, color.yellow, no);

# -----------------------------
#def upper2 = Round(clsline + (column_rng_ht/2), 2);
#def lower2 = Round(clsline - (column_rng_ht/2), 2);

# ------------------------------------
def lastbaroff = x;
def barbb = if lastbaroff  then 1 else 0;
def linebars = (lastbaroff or lastbaroff[-1] or lastbaroff[-2]);

# top and bottom, horz cloud levels
def up2b = if lastbaroff then upper2 else if lastbaroff[-1] then upper2[-1]  else if lastbaroff[-2] then upper2[-2] else na;
def low2b = if lastbaroff then lower2 else if lastbaroff[-1] then lower2[-1]  else if lastbaroff[-2] then lower2[-2] else na;

input price_bubbles = no;
def spb = price_bubbles;

def price_bubble_offset = 0;
#hint price_bubble_offset: Quantity of bars to shift the bubbles from the right edge of the column. - to the right, + to the left.
def po = price_bubble_offset;

# price bubbles
AddChartBubble(spb[-po] and barbb[-po], up2b[-po], up2b[-po], Color.CYAN, yes);
AddChartBubble(spb[-po] and barbb[-po], low2b[-po], low2b[-po], Color.CYAN, no);

# plot lines, to get price bubbles to appear on axis
plot z1 = up2b;
z1.setdefaultcolor(color.cyan);
plot z2 = low2b;
z2.setdefaultcolor(color.cyan);
#
#``````

My apologies, let me try it another way with an example.

Ticker closes at 50.25, then to draw a 4% bar, we'd take 50.25 X 0.96 = 48.24. Therefore the top of the cyan bar would begin at 50.25 (closing price) and end 4% lower at 48.24.

#### halcyonguy

##### Well-known member
VIP
Last edited by a moderator:

#### DSG

##### New member
• halcyonguy ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?