Script for Prior Highs and Lows for X number of Bars

timst454

New member
I've been working and working to try to draw a horizontal line from the High and Low of every bar for the past X number of days forward. To be clear I want the lines to extend horizontally through the other bars to today. I realize this is going to create a lot of horizontal lines. Everything I've done in ThinkorSwim as a script will only draw a line to the next bar. The other thing it will do is create a band around price by connecting each high and low together which is not what I want. I'm beginning to think TOS does not have the ability to draw horizontal lines out to today. Does anyone know what else I can try? Seems like a simple request. I've been able to create it in TradingView. When I ask ChatGPT to convert it to TOS it still comes back as a line above and below the current bar only.
 
I've been working and working to try to draw a horizontal line from the High and Low of every bar for the past X number of days forward. To be clear I want the lines to extend horizontally through the other bars to today. I realize this is going to create a lot of horizontal lines. Everything I've done in ThinkorSwim as a script will only draw a line to the next bar. The other thing it will do is create a band around price by connecting each high and low together which is not what I want. I'm beginning to think TOS does not have the ability to draw horizontal lines out to today. Does anyone know what else I can try? Seems like a simple request. I've been able to create it in TradingView. When I ask ChatGPT to convert it to TOS it still comes back as a line above and below the current bar only.

hello and welcome

your request is a little vague, so its unclear how many lines you expect to see.
if you have a chart set to 5 day , 1 minute , that would have 5 x 390 bars = 1950 bars. x 2 = 3900 lines. that would be ridiculous and completely cover the bars.

for every unique line on a bar, it needs to have its own plot line.
if you want to see 10 lines going over a bar, need 10 plots.
can't do plotting within a loop.

what do you really want to see on the chart?
use the drawing tool and markup a chart and post a screenshot.
 

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

I've been working and working to try to draw a horizontal line from the High and Low of every bar for the past X number of days forward. To be clear I want the lines to extend horizontally through the other bars to today. I realize this is going to create a lot of horizontal lines. Everything I've done in ThinkorSwim as a script will only draw a line to the next bar. The other thing it will do is create a band around price by connecting each high and low together which is not what I want. I'm beginning to think TOS does not have the ability to draw horizontal lines out to today. Does anyone know what else I can try? Seems like a simple request. I've been able to create it in TradingView. When I ask ChatGPT to convert it to TOS it still comes back as a line above and below the current bar only.

Choice to use Chart TimeFrame or Manual TimeFrame
Select up to 10 lines to plot. More plots can be easily created using the code logic for the 10
The image shows a Manual 15min on a 1min chart in the upper panel.
The image shows a Corresponding Chart Timeframe of 15min for comparison in the lower panel
Optional test bubbles are shown to display the Highs/Lows

Screenshot 2024-10-02 094849.jpg
Code:
#High_Low_Display_xLines_Extended_to_Right_Edge

input show_number_of_lines = 3;
input mode  = {default Chart_Time_Frame, Manual_Time_frame};
input agg    = AggregationPeriod.THIRTY_MIN;
input labels = yes;
def Time_Frame = if mode == mode.Chart_Time_Frame then GetAggregationPeriod() else agg;
AddLabel(labels, "Mode: " + mode + " - " + Time_Frame / 60000 + "min" , Color.YELLOW);

def H = if IsNaN(close) then H[1] else if mode == mode.Manual_Time_frame then high(period = Time_Frame) else high;
def L = if IsNaN(close) then L[1] else if mode == mode.Manual_Time_frame then low(period = Time_Frame) else low;
def C = if IsNaN(close) then C[1] else if mode == mode.Manual_Time_frame then close(period = Time_Frame) else close;
def O = if IsNaN(close) then O[1] else if mode == mode.Manual_Time_frame then open(period = Time_Frame) else open;

def NA   = Double.NaN;
def last = if !IsNaN(close) and (H[1] + L[1] + C[1] + O[1]) != (H + L + C + O) then last[1] + 1 else last[1];
def cond = HighestAll(last) - last + 1;

plot h1  = if cond > 1 or show_number_of_lines < 1 then NA else HighestAll(if (cond) == 1 then H else NA);
plot h2  = if cond > 2 or show_number_of_lines < 2 then NA else HighestAll(if (cond) == 2 then H else NA);
plot h3  = if cond > 3 or show_number_of_lines < 3 then NA else HighestAll(if (cond) == 3 then H else NA);
plot h4  = if cond > 4 or show_number_of_lines < 4 then NA else HighestAll(if (cond) == 4 then H else NA);
plot h5  = if cond > 5 or show_number_of_lines < 5 then NA else HighestAll(if (cond) == 5 then H else NA);
plot h6  = if cond > 6 or show_number_of_lines < 6 then NA else HighestAll(if (cond) == 6 then H else NA);
plot h7  = if cond > 7 or show_number_of_lines < 7 then NA else HighestAll(if (cond) == 7 then H else NA);
plot h8  = if cond > 8 or show_number_of_lines < 8 then NA else HighestAll(if (cond) == 8 then H else NA);
plot h9  = if cond > 9 or show_number_of_lines < 9 then NA else HighestAll(if (cond) == 9 then H else NA);
plot h10  = if cond > 10 or show_number_of_lines < 10 then NA else HighestAll(if (cond) == 10 then H else NA);

plot L1  = if cond > 1 or show_number_of_lines < 1 then NA else HighestAll(if (cond) == 1 then L else NA);
plot L2  = if cond > 2 or show_number_of_lines < 2 then NA else HighestAll(if (cond) == 2 then L else NA);
plot L3  = if cond > 3 or show_number_of_lines < 3 then NA else HighestAll(if (cond) == 3 then L else NA);
plot L4  = if cond > 4 or show_number_of_lines < 4 then NA else HighestAll(if (cond) == 4 then L else NA);
plot L5  = if cond > 5 or show_number_of_lines < 5 then NA else HighestAll(if (cond) == 5 then L else NA);
plot L6  = if cond > 6 or show_number_of_lines < 6 then NA else HighestAll(if (cond) == 6 then L else NA);
plot L7  = if cond > 7 or show_number_of_lines < 7 then NA else HighestAll(if (cond) == 7 then L else NA);
plot L8  = if cond > 8 or show_number_of_lines < 8 then NA else HighestAll(if (cond) == 8 then L else NA);
plot L9  = if cond > 9 or show_number_of_lines < 9 then NA else HighestAll(if (cond) == 9 then L else NA);
plot L10  = if cond > 10 or show_number_of_lines < 10 then NA else HighestAll(if (cond) == 10 then L else NA);

DefineGlobalColor("H", Color.GREEN);
DefineGlobalColor("L", Color.RED);

h1.SetDefaultColor(GlobalColor("H"));
h2.SetDefaultColor(GlobalColor("H"));
h3.SetDefaultColor(GlobalColor("H"));
h4.SetDefaultColor(GlobalColor("H"));
h5.SetDefaultColor(GlobalColor("H"));
h6.SetDefaultColor(GlobalColor("H"));
h7.SetDefaultColor(GlobalColor("H"));
h8.SetDefaultColor(GlobalColor("H"));
h9.SetDefaultColor(GlobalColor("H"));
h10.SetDefaultColor(GlobalColor("H"));

L1.SetDefaultColor(GlobalColor("L"));
L2.SetDefaultColor(GlobalColor("L"));
L3.SetDefaultColor(GlobalColor("L"));
L4.SetDefaultColor(GlobalColor("L"));
L5.SetDefaultColor(GlobalColor("L"));
L6.SetDefaultColor(GlobalColor("L"));
L7.SetDefaultColor(GlobalColor("L"));
L8.SetDefaultColor(GlobalColor("L"));
L9.SetDefaultColor(GlobalColor("L"));
L10.SetDefaultColor(GlobalColor("L"));

input test = no;
AddChartBubble(test and cond <= show_number_of_lines, H, cond, Color.YELLOW);
AddChartBubble(test and cond <= show_number_of_lines, L, cond, Color.WHITE, no);

#
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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