@truman How about this. Plots a line back from the current close and highlights any bar the line crosses.
Ruby:
#Svanoy
#HighLight bars with current close in range.
input offset = 1000;
def bar = BarNumber();
def VBar = if !IsNaN(close) and BarNumber()>0 then bar else VBar[1];
def VBarT = if !IsNaN(close[-offset]) then VBar[-offset] else VBart[1];
def FinalClose = fold c = 0 to VBarT while !IsNaN(GetValue(close, -c)) do GetValue(close, -c);
def FinalCloseLine = fold fcl = 0 to 1 do FinalClose;
def HighLightBar = fold hlb = 0 to VBarT while high >= FinalCloseLine and low <= FinalCloseLine and !IsNaN(close[-1]) do GetValue(BarNumber(), 0);
plot DayClose = if FinalClose > 0 then FinalClose else Double.NaN;
DayClose.SetStyle(Curve.LONG_DASH);
DayClose.AssignValueColor(Color.LIME);
AssignPriceColor(if HighLightBar != 0 then Color.BLUE else Color.CURRENT);
EDIT... post#2 code has been fixed.
------------------------
as of 3/1/22 1pm there is a typo in post #2 code
in this line,
#def VBarT = if !IsNaN(close[-offset]) then VBar[-offset] else VBart[1];
the ! should be removed from !isnan(
to be like this,
def VBarT = if IsNaN(close[-offset]) then VBar[-offset] else VBart[1];
-------------------------------------------------
i'm sure svanoy already knows this.
i am typing all this out so that others can learn some debugging steps.
the study didn't draw a line or highlight any bars on my chart.
i thought it was because i may have other studies that have an AssignPriceColor( ) function.
i have seen when 2 or more studied are loaded , that have that function, they may interfere with each other, and the bar coloring may be wrong.
i added a bubble to display some values. the "\n" causes the text after it to be moved to a new text line.
i prefer 1 bubble this way.
you can also use many bubbles. IF they all use the same price position, they will appear stacked. if not, they will overlap each other.
i used a constant , 150 for price, so bubbles would draw after the last bar. ( low would cause the bubbles to stop on the last bar).
nothing magic about 150, it was just a price that was near the close price.
i noticed vbart was always 0.
Code:
input test1 = no;
addchartbubble(test1, 150,
bar + " bar\n" +
vbar + " vbar\n" +
vbart + " vbart\n" +
FinalClose + " fc\n" +
FinalCloseLine + " fcl\n"
, color.yellow, no);
bubbles, before fix
i compared the code to this version that i have. ( i have 100s of code snippets saved as text files)
i compared the bnlast formula. i tried removing the !, and it worked.
Code:
def bn = barnumber();
input barsBack = 1000;
def d = if !IsNaN(close) and IsNaN(close[-1])
then bn
else d[1];
def bnlast = if isNaN(close[-barsBack])
then d[-barsBack]
else Double.NaN;
addchartbubble(1, 150, bn + "\n" + d + "\n" + bnlast, color.cyan, yes);
#
after fix - vbart had the number of the last bar
ref
Current Price Line Indicator For ThinkOrSwim
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
hal_debug