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 am rereading your posts and coming up with new questions.
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
# https://usethinkscript.com/threads/can-anyone-code-plot-for-measuring-percentage-on-a-chart.10281/
# 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[1];
def clsline = if IsNaN(close[-barsBack])
then c[-barsBack]
else Double.NaN;
# ------------------------------------
#def lastbar = (!IsNaN(cls[0]) 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);
addlabel(show_column_ht_label, column_height_type , 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);
addchartbubble(0, 53,
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);
AddCloud( up2b, low2b, Color.cyan, Color.cyan);
# plot lines, to get price bubbles to appear on axis
plot z1 = up2b;
z1.setdefaultcolor(color.cyan);
plot z2 = low2b;
z2.setdefaultcolor(color.cyan);
#
#