good job on trying something. it wasn't right, but you tried. keep on experimenting and learning.
getvalue has nothing to do with rounding a number. it reads a variable , x bars away from the current bar.
in your case,
. plot ph = GetValue(A, 2);
is using an offset of 2 to read A.
that means it is looking back 2 bars and reading the value of A. that is why the numbers are 'on the line'.
the numbers are not from the candle that triggered the line to be drawn. they are the wrong numbers.
i added this to change how many digits are shown.
def digits = if close < 0.01 then 6 else if close < 1 then 4 else 2;
plot ph = Round(A, digits);
plot pL = Round(B, digits);
if there are trailing zeros, they will not be shown. ( 0.4100 will be 0.41 )
tested with
OGEN 0.4425
ACRX 0.4850
SGMD 0.00085
Ruby:
# peakhorzlines_6digits_00c
# add digits formula for rounding to 2,4,6 digits
# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# jpwel added alerts 06/26/2015
input n = 8;
input ShowLines = yes;
input SoundAlerts = yes;
def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1
to n + 1
with p = 1
while p
do h > GetValue(h, -i);
def A = if (Firstbar > n
and h == Highest(h, n)
and Highest)
then h
else Double.NaN;
def Lowest = fold j = 1
to n + 1
with q = 1
while q
do l < GetValue(l, -j);
def B = if (Firstbar > n
and l == Lowest(l, n)
and Lowest)
then l
else Double.NaN;
rec Al = if !IsNaN(A)
then A
else Al[1];
rec Bl = if !IsNaN(B)
then B
else Bl[1];
def digits = if close < 0.01 then 6 else if close < 1 then 4 else 2;
plot ph = Round(A, digits);
#plot ph = Round(A, 2);
ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
plot hL = if Al > 0
then Al
else Double.NaN;
hL.SetHiding(!ShowLines);
hL.SetPaintingStrategy(PaintingStrategy.DASHES);
hL.SetDefaultColor(Color.GREEN);
plot pL = Round(B, digits);
#plot pl = Round(B,2);
pl.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
plot ll = if Bl > 0
then Bl
else Double.NaN;
ll.SetHiding(!ShowLines);
ll.SetPaintingStrategy(PaintingStrategy.DASHES);
ll.SetDefaultColor(Color.RED);
#
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetValue