Horizontal High/Low Lines for the 10 Bars

samhanoh

New member
VIP
Hi everyone,
I'm looking for help creating a ThinkScript study that meets the following conditions:

🔹 Requirements:
  1. Plot two horizontal lines:
    • One for the highest high from the 10 bars before yesterday.
    • One for the lowest low from the same 10 bars.
  2. These lines should:
    • Be perfectly horizontal (i.e., fixed value, not changing every bar).
    • Display for only the most recent 10 bars on the chart.
    • Update automatically every new bar (so as time moves forward, the lines shift forward too, based on the 10-bar window ending at the bar before the current one).
 

Attachments

  • ScreenHunter 951.jpg
    ScreenHunter 951.jpg
    20.6 KB · Views: 24
Last edited by a moderator:
Solution
Ruby:
Input Length = 10;

Def BarNumber = if !IsNaN(close) then BarNumber() else Double.NaN;
Def LastBar = HighestAll(BarNumber);

Def HHigh = Highest(high,Length);
Def LLow = Lowest(low,Length);

Plot HLine = if LastBar-BarNumber<Length+1 && LastBar-BarNumber>0 then GetValue(HHigh,-(LastBar-BarNumber)+1) else Double.NaN;;
HLine.SetPaintingStrategy(PaintingStrategy.DASHES);
HLine.SetDefaultColor(Color.Yellow);
Plot LLine = if LastBar-BarNumber<Length+1 && LastBar-BarNumber>0 then GetValue(LLow,-(LastBar-BarNumber)+1) else Double.NaN;;
LLine.SetPaintingStrategy(PaintingStrategy.DASHES);
LLine.SetDefaultColor(Color.Yellow);
56bMD5E.jpeg
Ruby:
Input Length = 10;

Def BarNumber = if !IsNaN(close) then BarNumber() else Double.NaN;
Def LastBar = HighestAll(BarNumber);

Def HHigh = Highest(high,Length);
Def LLow = Lowest(low,Length);

Plot HLine = if LastBar-BarNumber<Length+1 && LastBar-BarNumber>0 then GetValue(HHigh,-(LastBar-BarNumber)+1) else Double.NaN;;
HLine.SetPaintingStrategy(PaintingStrategy.DASHES);
HLine.SetDefaultColor(Color.Yellow);
Plot LLine = if LastBar-BarNumber<Length+1 && LastBar-BarNumber>0 then GetValue(LLow,-(LastBar-BarNumber)+1) else Double.NaN;;
LLine.SetPaintingStrategy(PaintingStrategy.DASHES);
LLine.SetDefaultColor(Color.Yellow);
56bMD5E.jpeg
 
Solution

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
411 Online
Create Post

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