Horizontal line after condition met

Can anyone help with coding a study that will draw a horizontal line once a condition is met? To simplify, here is an example:

Once a bar has closed five ticks above the close of the opening bar, draw a horizonal line, starting from the close of the bar that broke the five tick barrier.

I am able to get a horizontal line to draw, but the line moves as soon as another bar closes above the original line. I would like the original line to remain fixed from the point of the bar that met the condition.

My problem is that I am defining a condition that is recalculated on each bar, so it will draw a new one when the condition is met. I can't figure out the language to say "leave the line in place once the condition has been met".

I think the answer is in this post, but I can't figure it out: https://usethinkscript.com/threads/thinkscript-barnumber-function-usage-and-examples.673/

Thanks!
 
Last edited:
Solution
Can anyone help with coding a study that will draw a horizontal line once a condition is met? To simplify, here is an example:

Once a bar has closed five ticks above the close of the opening bar, draw a horizonal line, starting from the close of the bar that broke the five tick barrier.

I am able to get a horizontal line to draw, but the line moves as soon as another bar closes above the original line. I would like the original line to remain fixed from the point of the bar that met the condition.

My problem is that I am defining a condition that is recalculated on each bar, so it will draw a new one when the condition is met. I can't figure out the language to say "leave the line in place once the condition has been met".

I...
Can anyone help with coding a study that will draw a horizontal line once a condition is met? To simplify, here is an example:

Once a bar has closed five ticks above the close of the opening bar, draw a horizonal line, starting from the close of the bar that broke the five tick barrier.

I am able to get a horizontal line to draw, but the line moves as soon as another bar closes above the original line. I would like the original line to remain fixed from the point of the bar that met the condition.

My problem is that I am defining a condition that is recalculated on each bar, so it will draw a new one when the condition is met. I can't figure out the language to say "leave the line in place once the condition has been met".

I think the answer is in this post, but I can't figure it out: https://usethinkscript.com/threads/thinkscript-barnumber-function-usage-and-examples.673/

Thanks!

Here is one way

Capture.jpg
Ruby:
def bn     = BarNumber();

def o      = if GetDay() == GetLastDay() and
                GetTime() crosses above RegularTradingStart(GetYYYYMMDD())
             then close
             else o[1];

def break  = if close >= o[1] + 5 * TickSize()
             then bn
             else Double.NaN;

def xclose = if bn == LowestAll(break)
             then close
             else xclose[1];

plot break_close = xclose;
break_close.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
411 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