Grid of Multiple Horizontal lines

JRAY

New member
Plus
This is nice indicator, does anyone know how to make a simple version of this that will draw simple horizontal lines from the current price, each line at a set interval (distance) of each other? As in the chart below, there are 2 lines above and below the center line (current price), each line is at 2 pt distance. Each line with unique identification and alert triggered when touched. Interval and number of lines are user selectable. thanks
1724322393162.png


Thank you so much for your great work in this forum. I saw the great work done on this Auto Support/Resistance breakout. https://usethinkscript.com/threads/auto-resistance-support-break-detector.2178/
This could be done manually but it takes time, especially if you want to track many instruments and get alerted. So I was wondering if someone could help with the creation of a Grid Indicator that will populate simple Static Horizontal lines above and below the current price, each at a fix interval (could be 10 point or 1000 point distance) and each line with its own and unique identifier?
In the case below, there is grid of 8 equidistant lines, 4 on each side of the current price. (line touching the current price level does not count, just a reference point). Thanks a bunch..
1724320544692.png
 
Solution
This is nice indicator, does anyone know how to make a simple version of this that will draw simple horizontal lines from the current price, each line at a set interval (distance) of each other? As in the chart below, there are 2 lines above and below the center line (current price), each line is at 2 pt distance. Each line with unique identification and alert triggered when touched. Interval and number of lines are user selectable. thanks

Thank you so much for your great work in this forum. I saw the great work done on this Auto Support/Resistance breakout. https://usethinkscript.com/threads/auto-resistance-support-break-detector.2178/
This could be done manually but it takes time, especially if you want to track many...
This is nice indicator, does anyone know how to make a simple version of this that will draw simple horizontal lines from the current price, each line at a set interval (distance) of each other? As in the chart below, there are 2 lines above and below the center line (current price), each line is at 2 pt distance. Each line with unique identification and alert triggered when touched. Interval and number of lines are user selectable. thanks

Thank you so much for your great work in this forum. I saw the great work done on this Auto Support/Resistance breakout. https://usethinkscript.com/threads/auto-resistance-support-break-detector.2178/
This could be done manually but it takes time, especially if you want to track many instruments and get alerted. So I was wondering if someone could help with the creation of a Grid Indicator that will populate simple Static Horizontal lines above and below the current price, each at a fix interval (could be 10 point or 1000 point distance) and each line with its own and unique identifier?
In the case below, there is grid of 8 equidistant lines, 4 on each side of the current price. (line touching the current price level does not count, just a reference point). Thanks a bunch..


Code:
#lines_horz_mult_from_close
#https://usethinkscript.com/threads/grid-of-multiple-horizontal-lines.19487/
#Grid of Multiple Horizontal lines

input line_spacing = 2.0;

#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# Line At Price
# Mobius
input barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
        then close
        else c[1];
def cline = if isNaN(close[-barsBack])
            then c[-barsBack]
            else Double.NaN;

plot z0 = cline;
plot y1 = cline + (1 * line_spacing);
plot y2 = cline + (2 * line_spacing);
plot y3 = cline + (3 * line_spacing);
plot y4 = cline + (4 * line_spacing);

plot z1 = cline - (1 * line_spacing);
plot z2 = cline - (2 * line_spacing);
plot z3 = cline - (3 * line_spacing);
plot z4 = cline - (4 * line_spacing);

z0.SetDefaultColor(Color.cyan);
y1.SetDefaultColor(Color.gray);
y2.SetDefaultColor(Color.gray);
y3.SetDefaultColor(Color.gray);
y4.SetDefaultColor(Color.gray);
z1.SetDefaultColor(Color.gray);
z2.SetDefaultColor(Color.gray);
z3.SetDefaultColor(Color.gray);
z4.SetDefaultColor(Color.gray);
#
 
Solution

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

Code:
#lines_horz_mult_from_close
#https://usethinkscript.com/threads/grid-of-multiple-horizontal-lines.19487/
#Grid of Multiple Horizontal lines

input line_spacing = 2.0;

#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# Line At Price
# Mobius
input barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
        then close
        else c[1];
def cline = if isNaN(close[-barsBack])
            then c[-barsBack]
            else Double.NaN;

plot z0 = cline;
plot y1 = cline + (1 * line_spacing);
plot y2 = cline + (2 * line_spacing);
plot y3 = cline + (3 * line_spacing);
plot y4 = cline + (4 * line_spacing);

plot z1 = cline - (1 * line_spacing);
plot z2 = cline - (2 * line_spacing);
plot z3 = cline - (3 * line_spacing);
plot z4 = cline - (4 * line_spacing);

z0.SetDefaultColor(Color.cyan);
y1.SetDefaultColor(Color.gray);
y2.SetDefaultColor(Color.gray);
y3.SetDefaultColor(Color.gray);
y4.SetDefaultColor(Color.gray);
z1.SetDefaultColor(Color.gray);
z2.SetDefaultColor(Color.gray);
z3.SetDefaultColor(Color.gray);
z4.SetDefaultColor(Color.gray);
#
Thank you so much. Great work. Is it possible for the user to insert the starting price from which the GRID is build? also add alert when each line is touched or crossed?
 
can pick a price line for the center line. if = 0 then it follows the current price.
if a price is picked, then alerts may go off.
can turn on vertical lines to verify crossing bars.


Code:
#lines_horz_mult_from_close_02

#https://usethinkscript.com/threads/grid-of-multiple-horizontal-lines.19487/
#Grid of Multiple Horizontal lines

def na = double.nan;
def bn = barnumber();

input price_level = 0;
#hint price_level: Enter a price level, or 0 to follow current price

input line_spacing = 2.0;
def cls = close;

#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# Line At Price
# Mobius
input barsBack = 1000;
def c = if !IsNaN(cls) and IsNaN(cls[-1]) then cls else c[1];
def cline = if isNaN(cls[-barsBack]) then c[-barsBack] else na;


def base = if price_level > 0 then price_level else cline;
plot z0 = base;
plot z1 = base + (1 * line_spacing);
plot z2 = base + (2 * line_spacing);
plot z3 = base + (3 * line_spacing);
plot z4 = base + (4 * line_spacing);
plot z5 = base - (1 * line_spacing);
plot z6 = base - (2 * line_spacing);
plot z7 = base - (3 * line_spacing);
plot z8 = base - (4 * line_spacing);
z0.SetDefaultColor(Color.cyan);
z1.SetDefaultColor(Color.gray);
z2.SetDefaultColor(Color.gray);
z3.SetDefaultColor(Color.gray);
z4.SetDefaultColor(Color.gray);
z5.SetDefaultColor(Color.gray);
z6.SetDefaultColor(Color.gray);
z7.SetDefaultColor(Color.gray);
z8.SetDefaultColor(Color.gray);


def x0 = cls crosses z0;
def x1 = cls crosses z1;
def x2 = cls crosses z2;
def x3 = cls crosses z3;
def x4 = cls crosses z4;
def x5 = cls crosses z5;
def x6 = cls crosses z6;
def x7 = cls crosses z7;
def x8 = cls crosses z8;

input alerts = yes;
alert(alerts and x0, ("crossed " + x0) ,alert.BAR, sound.DING);
alert(alerts and x1, ("crossed " + x1) ,alert.BAR, sound.DING);
alert(alerts and x2, ("crossed " + x2) ,alert.BAR, sound.DING);
alert(alerts and x3, ("crossed " + x3) ,alert.BAR, sound.DING);
alert(alerts and x4, ("crossed " + x4) ,alert.BAR, sound.DING);
alert(alerts and x5, ("crossed " + x5) ,alert.BAR, sound.DING);
alert(alerts and x6, ("crossed " + x6) ,alert.BAR, sound.DING);
alert(alerts and x7, ("crossed " + x7) ,alert.BAR, sound.DING);
alert(alerts and x8, ("crossed " + x8) ,alert.BAR, sound.DING);


input test_lines = no;
addverticalline(test_lines and x0, z0);
addverticalline(test_lines and x1, z1);
addverticalline(test_lines and x2, z2);
addverticalline(test_lines and x3, z3);
addverticalline(test_lines and x4, z4);
addverticalline(test_lines and x5, z5);
addverticalline(test_lines and x6, z6);
addverticalline(test_lines and x7, z7);
addverticalline(test_lines and x8, z8);
#
 
can pick a price line for the center line. if = 0 then it follows the current price.
if a price is picked, then alerts may go off.
can turn on vertical lines to verify crossing bars.


Code:
#lines_horz_mult_from_close_02

#https://usethinkscript.com/threads/grid-of-multiple-horizontal-lines.19487/
#Grid of Multiple Horizontal lines

def na = double.nan;
def bn = barnumber();

input price_level = 0;
#hint price_level: Enter a price level, or 0 to follow current price

input line_spacing = 2.0;
def cls = close;

#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# Line At Price
# Mobius
input barsBack = 1000;
def c = if !IsNaN(cls) and IsNaN(cls[-1]) then cls else c[1];
def cline = if isNaN(cls[-barsBack]) then c[-barsBack] else na;


def base = if price_level > 0 then price_level else cline;
plot z0 = base;
plot z1 = base + (1 * line_spacing);
plot z2 = base + (2 * line_spacing);
plot z3 = base + (3 * line_spacing);
plot z4 = base + (4 * line_spacing);
plot z5 = base - (1 * line_spacing);
plot z6 = base - (2 * line_spacing);
plot z7 = base - (3 * line_spacing);
plot z8 = base - (4 * line_spacing);
z0.SetDefaultColor(Color.cyan);
z1.SetDefaultColor(Color.gray);
z2.SetDefaultColor(Color.gray);
z3.SetDefaultColor(Color.gray);
z4.SetDefaultColor(Color.gray);
z5.SetDefaultColor(Color.gray);
z6.SetDefaultColor(Color.gray);
z7.SetDefaultColor(Color.gray);
z8.SetDefaultColor(Color.gray);


def x0 = cls crosses z0;
def x1 = cls crosses z1;
def x2 = cls crosses z2;
def x3 = cls crosses z3;
def x4 = cls crosses z4;
def x5 = cls crosses z5;
def x6 = cls crosses z6;
def x7 = cls crosses z7;
def x8 = cls crosses z8;

input alerts = yes;
alert(alerts and x0, ("crossed " + x0) ,alert.BAR, sound.DING);
alert(alerts and x1, ("crossed " + x1) ,alert.BAR, sound.DING);
alert(alerts and x2, ("crossed " + x2) ,alert.BAR, sound.DING);
alert(alerts and x3, ("crossed " + x3) ,alert.BAR, sound.DING);
alert(alerts and x4, ("crossed " + x4) ,alert.BAR, sound.DING);
alert(alerts and x5, ("crossed " + x5) ,alert.BAR, sound.DING);
alert(alerts and x6, ("crossed " + x6) ,alert.BAR, sound.DING);
alert(alerts and x7, ("crossed " + x7) ,alert.BAR, sound.DING);
alert(alerts and x8, ("crossed " + x8) ,alert.BAR, sound.DING);


input test_lines = no;
addverticalline(test_lines and x0, z0);
addverticalline(test_lines and x1, z1);
addverticalline(test_lines and x2, z2);
addverticalline(test_lines and x3, z3);
addverticalline(test_lines and x4, z4);
addverticalline(test_lines and x5, z5);
addverticalline(test_lines and x6, z6);
addverticalline(test_lines and x7, z7);
addverticalline(test_lines and x8, z8);
#
This is great. Thanks again. I really appreciate. Testing further.
 
@halcyonguy

I hope I'm not being too picky, but is there a way to get 7 lines instead of just 4? It's very important concerning means reversions where seven would be the 2nd sigma level... That would be awesome!
 
Last edited by a moderator:
@halcyonguy

I hope I'm not being too picky, but is there a way to get 7 lines instead of just 4? It's very important concerning means reversions where seven would be the 2nd sigma level... That would be awesome!

this can draw up to 8 lines
can pick how many lines 1 - 8
can pick type of line spacing , a number or ATR
pick a line spacing factor , default of 1


Code:
#lines_horz_mult_from_close_03

def na = double.nan;
def bn = barnumber();

input price_level = 0;
#hint price_level: Enter a price level, or 0 to follow current price

input line_spacing_type = { default constant, atr };
# hint line_spacing_type: Pick line spacing type, a number or ATR

input line_spacing = 2.0;
input line_qty = 2;
input spacing_factor = 1.0;
def cls = close;

#----------------------
# ATR
def length = 14;
def averageType = AverageType.WILDERS;
def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
#----------------------

#---------------------
#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# Line At Price
# Mobius
input barsBack = 1000;
def c = if !IsNaN(cls) and IsNaN(cls[-1]) then cls else c[1];
def cline = if isNaN(cls[-barsBack]) then c[-barsBack] else na;
#--------------------

def base = if price_level > 0 then price_level else cline;

def spac;
switch (line_spacing_type) {
case constant:
 spac = line_spacing;
case atr:
 spac = atr;
}

plot z0 = if isnan(close[1]) then na else base;
plot u1 = if !isnan(close) and line_qty >= 1 then (base + (1 * spac * spacing_factor)) else na;
plot u2 = if !isnan(close) and line_qty >= 2 then (base + (2 * spac * spacing_factor)) else na;
plot u3 = if !isnan(close) and line_qty >= 3 then (base + (3 * spac * spacing_factor)) else na;
plot u4 = if !isnan(close) and line_qty >= 4 then (base + (4 * spac * spacing_factor)) else na;
plot u5 = if !isnan(close) and line_qty >= 5 then (base + (5 * spac * spacing_factor)) else na;
plot u6 = if !isnan(close) and line_qty >= 6 then (base + (6 * spac * spacing_factor)) else na;
plot u7 = if !isnan(close) and line_qty >= 7 then (base + (7 * spac * spacing_factor)) else na;
plot u8 = if !isnan(close) and line_qty >= 8 then (base + (8 * spac * spacing_factor)) else na;

plot w1 = if !isnan(close) and line_qty >= 1 then (base - (1 * spac * spacing_factor)) else na;
plot w2 = if !isnan(close) and line_qty >= 2 then (base - (2 * spac * spacing_factor)) else na;
plot w3 = if !isnan(close) and line_qty >= 3 then (base - (3 * spac * spacing_factor)) else na;
plot w4 = if !isnan(close) and line_qty >= 4 then (base - (4 * spac * spacing_factor)) else na;
plot w5 = if !isnan(close) and line_qty >= 5 then (base - (5 * spac * spacing_factor)) else na;
plot w6 = if !isnan(close) and line_qty >= 6 then (base - (6 * spac * spacing_factor)) else na;
plot w7 = if !isnan(close) and line_qty >= 7 then (base - (7 * spac * spacing_factor)) else na;
plot w8 = if !isnan(close) and line_qty >= 8 then (base - (8 * spac * spacing_factor)) else na;

z0.SetDefaultColor(Color.cyan);
u1.SetDefaultColor(Color.gray);
u2.SetDefaultColor(Color.gray);
u3.SetDefaultColor(Color.gray);
u4.SetDefaultColor(Color.gray);
u5.SetDefaultColor(Color.gray);
u6.SetDefaultColor(Color.gray);
u7.SetDefaultColor(Color.gray);
u8.SetDefaultColor(Color.gray);

w1.SetDefaultColor(Color.gray);
w2.SetDefaultColor(Color.gray);
w3.SetDefaultColor(Color.gray);
w4.SetDefaultColor(Color.gray);
w5.SetDefaultColor(Color.gray);
w6.SetDefaultColor(Color.gray);
w7.SetDefaultColor(Color.gray);
w8.SetDefaultColor(Color.gray);


def xz0 = cls crosses z0;
def xu1 = cls crosses u1;
def xu2 = cls crosses u2;
def xu3 = cls crosses u3;
def xu4 = cls crosses u4;
def xu5 = cls crosses u5;
def xu6 = cls crosses u6;
def xu7 = cls crosses u7;
def xu8 = cls crosses u8;

def xw1 = cls crosses w1;
def xw2 = cls crosses w2;
def xw3 = cls crosses w3;
def xw4 = cls crosses w4;
def xw5 = cls crosses w5;
def xw6 = cls crosses w6;
def xw7 = cls crosses w7;
def xw8 = cls crosses w8;

input alerts = yes;
alert(alerts and xz0, ("crossed " + xz0) ,alert.BAR, sound.DING);
alert(alerts and xu1, ("crossed " + xu1) ,alert.BAR, sound.DING);
alert(alerts and xu2, ("crossed " + xu2) ,alert.BAR, sound.DING);
alert(alerts and xu3, ("crossed " + xu3) ,alert.BAR, sound.DING);
alert(alerts and xu4, ("crossed " + xu4) ,alert.BAR, sound.DING);
alert(alerts and xu5, ("crossed " + xu5) ,alert.BAR, sound.DING);
alert(alerts and xu6, ("crossed " + xu6) ,alert.BAR, sound.DING);
alert(alerts and xu7, ("crossed " + xu7) ,alert.BAR, sound.DING);
alert(alerts and xu8, ("crossed " + xu8) ,alert.BAR, sound.DING);

alert(alerts and xw1, ("crossed " + xw1) ,alert.BAR, sound.DING);
alert(alerts and xw2, ("crossed " + xw2) ,alert.BAR, sound.DING);
alert(alerts and xw3, ("crossed " + xw3) ,alert.BAR, sound.DING);
alert(alerts and xw4, ("crossed " + xw4) ,alert.BAR, sound.DING);
alert(alerts and xw5, ("crossed " + xw4) ,alert.BAR, sound.DING);
alert(alerts and xw6, ("crossed " + xw4) ,alert.BAR, sound.DING);
alert(alerts and xw7, ("crossed " + xw4) ,alert.BAR, sound.DING);
alert(alerts and xw8, ("crossed " + xw4) ,alert.BAR, sound.DING);

#---------------------

addlabel(1, "    ", color.black);
addlabel(1, "price level " +  price_level, color.yellow);
addlabel(1, "base price " + base, color.yellow);
addlabel(1, "line qty " + line_qty, color.yellow);
addlabel(1, "spacing factor " + spacing_factor, color.yellow);
addlabel(1, "line spacing " + line_spacing * spacing_factor , color.yellow);

input test_lines = no;
addverticalline(test_lines and xz0, z0);
addverticalline(test_lines and xu1, u1);
addverticalline(test_lines and xu2, u2);
addverticalline(test_lines and xu3, u3);
addverticalline(test_lines and xu4, u4);
addverticalline(test_lines and xu5, u5);
addverticalline(test_lines and xu6, u6);
addverticalline(test_lines and xu7, u7);
addverticalline(test_lines and xu8, u8);

addverticalline(test_lines and xw1, w1);
addverticalline(test_lines and xw2, w2);
addverticalline(test_lines and xw3, w3);
addverticalline(test_lines and xw4, w4);
addverticalline(test_lines and xw5, w5);
addverticalline(test_lines and xw6, w6);
addverticalline(test_lines and xw7, w7);
addverticalline(test_lines and xw8, w8);
#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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