Support resistance crosshairs highlight candles when crosshairs touch them.

truman

New member
I would like to request information on any ideas/Thinkscripts, on a Thinkscript that would cause all candles that a crosshairs touches to highlight when a crosshairs touches them. This would be for all candles that represent days, on, for example, a daily chart, to highlight when the price crosshairs rolls over them such that seeing support and resistance for all candles in a chart to be easily seen at every touch of the crosshairs down the line from newest date to earliest at the same time. The above script should make marking support and resistance levels based on a stocks price history easier and help eliminate missed levels.
 
Solution
@truman How about this. Plots a line back from the current close and highlights any bar the line crosses.

AlJb5nt.png

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...
@truman How about this. Plots a line back from the current close and highlights any bar the line crosses.

AlJb5nt.png

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);
 
Last edited:
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@truman
Updated the code above, Seems like TOS has nerfed the FOLD statements for passing a value backwards.
Edited to make use of alternative method.
The value of the input 'offset' has to be less than the number of bars in your chart,
Works in real time now.
 
Last edited:
@truman How about this. Plots a line back from the current close and highlights any bar the line crosses.

AlJb5nt.png

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
oMGHWYz.jpg


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
VwY8X1s.jpg


ref
Current Price Line Indicator For ThinkOrSwim
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
hal_debug
 
Last edited:
I'm glad you pointed this out, I had forgotten to come back and fix this.
Is now fixed.
Would like to add, whether or not it should be !IsNaN or IsNaN depends on if the value of offset is greater or less than the number of bars displayed on the chart. So it could go either way depending on the context.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
445 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top