How to plot horizontal lines at price levels where the price ends with a certain number

ikymerai

New member
Hi All,

New to the forum and trying to learn thinkscript...I'd like to create an indicator that plots horizontal lines at price levels where the price ends with a certain number (user input number), i.e. userPriceEndsWith = "1.50" so we want to plot horizontal lines at every price level on the chart where the price ends with "1.50"

What I'd like to do is plot horizontal lines at 1.50, 11.50, 21.50, 31.50 etc

How can one do this in thinkscript? Are there loops in the language? Any example(s) would be greatly appreciated

Thanks in advance for all your help!

Adam
 
Solution
I want to draw 2 horizontal lines across my charts (for daily and weekly views) where the high horizontal line is defined as the high of the first trading day of any week (obviously this is usually Monday unless a holiday week) and the low horizontal line is the low of the first trading day of the week. So these horizontal lines will change each week as new First Trading Day of the Week Highs and lows change. I would like the lines to persist on both daily and weekly charts.

This seems to work as you want for daily, however Monday is not available on weekly.

Screenshot 2024-08-05 095144.jpg
Code:
input show_last_only = no;
def start_day_week   = if GetWeek() != GetWeek()[1]
                       then if GetDayOfWeek(GetYYYYMMDD()) == 1...
Hi All,

New to the forum and trying to learn thinkscript...I'd like to create an indicator that plots horizontal lines at price levels where the price ends with a certain number (user input number), i.e. userPriceEndsWith = "1.50" so we want to plot horizontal lines at every price level on the chart where the price ends with "1.50"

What I'd like to do is plot horizontal lines at 1.50, 11.50, 21.50, 31.50 etc

How can one do this in thinkscript? Are there loops in the language? Any example(s) would be greatly appreciated

Thanks in advance for all your help!

Adam

you will need a plot function for each line you want. fold loops can repeat a formula x times, but it returns 1 number value. they can't include a plot. you can't have a loop repeat a plot many times.

below are ideas and formulas, may not be exact thinkscript codes.
the below formulas create instantaneous values.
you will have to search and find a study code that plots price line levels.

so you may want to do something like draw 3 lines above the current price, and 3 lines below it.
you could create a formula to find a multiple of 10, that is closest to the current price. call it baseline.

def basefactor = round( close /10, 0);
def baseline = basefactor * 10;

then add 3 numbers to it for lines above and subtract 3 numbers, for lines below.

def line1up = baseline + (10 + your number) ;
def line2up = baseline + (20 + your number) ;
def line3up = baseline + (30 + your number) ;

def line1dwn = baseline - (10 + your number) ;
def line2dwn = baseline - (20 + your number) ;
def line3dwn = baseline - (30 + your number);

then apply horizontal line formulas ( highestall(.... or whatever ) to each of the 7 values above.

here is an example code that draws a horizontal line.
https://usethinkscript.com/threads/how-to-plot-horizontal-line-in-thinkscript.836/#post-6832
 

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

you will need a plot function for each line you want. fold loops can repeat a formula x times, but it returns 1 number value. they can't include a plot. you can't have a loop repeat a plot many times.

here is a working study
it can plot up to 5 lines above and below the reference level, at some factor

Code:
# horz_lines_increm_near_close_0

# plot some quantity of horizontal lines,
# above and below a reference price near the close.
# the ref price is a multiple of the spacing_factor, that is closest to the close.

#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-74052

# Line At Price
# Mobius
# Alternative to using the HighestAll() function
def barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
        then close
        else c[1];
#plot line = if isNaN(close[-barsBack])
def line = if isNaN(close[-barsBack])
            then c[-barsBack]
            else Double.NaN;
#line.SetLineWeight(1);
#line.SetDefaultColor(Color.LIME);
#line.SetStyle(Curve.MEDIUM_DASH);

def na = double.nan;
input quantity_of_lines = 4;
def q = quantity_of_lines;

input spacing_factor = 0.5;
def basefactor = round( line/spacing_factor, 0);
def baseline = basefactor * spacing_factor;

plot b = baseline;
b.SetLineWeight(1);
b.SetDefaultColor(Color.LIME);
b.SetStyle(Curve.MEDIUM_DASH);

addlabel(1, " ", color.black);
addlabel(1, "baseline " + baseline, color.yellow);

plot line5up = if 5 > q then na else baseline + (spacing_factor * 5);
plot line4up = if 4 > q then na else baseline + (spacing_factor * 4);
plot line3up = if 3 > q then na else baseline + (spacing_factor * 3);
plot line2up = if 2 > q then na else baseline + (spacing_factor * 2);
plot line1up = if 1 > q then na else baseline + (spacing_factor * 1);

plot line1dwn = if 1 > q then na else baseline - (spacing_factor * 1);
plot line2dwn = if 2 > q then na else baseline - (spacing_factor * 2);
plot line3dwn = if 3 > q then na else baseline - (spacing_factor * 3);
plot line4dwn = if 4 > q then na else baseline - (spacing_factor * 4);
plot line5dwn = if 5 > q then na else baseline - (spacing_factor * 5);
#


AAL 5min
line spacing = 0.1
quatity of line = 4
9uzMwZe.jpg

hal_horz
 
Last edited:
I changed this study slightly to meet my needs for trading futures. All lines are 1 color, 5 lines, in each direction, and they are demarcated by 100s.


Code:
# horz_lines_increm_near_close_0

# plot some quantity of horizontal lines,
# above and below a reference price near the close.
# the ref price is a multiple of the spacing_factor, that is closest to the close.

#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-74052

# Line At Price
# Mobius
# Alternative to using the HighestAll() function

# 1/11/2023 - Cribbage: made all lines 1 color, # of lines = 5, quantity = 100

def barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
        then close
        else c[1];
#plot line = if isNaN(close[-barsBack])
def line = if isNaN(close[-barsBack])
            then c[-barsBack]
            else Double.NaN;
#line.SetLineWeight(2);
#line.SetDefaultColor(Color.LIME);
#line.SetStyle(Curve.MEDIUM_DASH);

def na = double.nan;
input quantity_of_lines = 5;
def q = quantity_of_lines;

input spacing_factor = 100;
def basefactor = round( line/spacing_factor, 0);
def baseline = basefactor * spacing_factor;

plot b = baseline;
b.SetLineWeight(2);
b.SetDefaultColor(Color.LIME);
b.SetStyle(Curve.MEDIUM_DASH);

addlabel(1, " ", color.black);
addlabel(1, "baseline " + baseline, color.yellow);

plot line5up = if 5 > q then na else baseline + (spacing_factor * 5);
plot line4up = if 4 > q then na else baseline + (spacing_factor * 4);
plot line3up = if 3 > q then na else baseline + (spacing_factor * 3);
plot line2up = if 2 > q then na else baseline + (spacing_factor * 2);
plot line1up = if 1 > q then na else baseline + (spacing_factor * 1);

line5up.SetDefaultColor(Color.LIME);
line5up.SetStyle(Curve.MEDIUM_DASH);
line5up.SetLineWeight(2);

line4up.SetDefaultColor(Color.LIME);
line4up.SetStyle(Curve.MEDIUM_DASH);
line4up.SetLineWeight(2);

line3up.SetDefaultColor(Color.LIME);
line3up.SetStyle(Curve.MEDIUM_DASH);
line3up.SetLineWeight(2);

line2up.SetDefaultColor(Color.LIME);
line2up.SetStyle(Curve.MEDIUM_DASH);
line2up.SetLineWeight(2);

line1up.SetDefaultColor(Color.LIME);
line1up.SetStyle(Curve.MEDIUM_DASH);
line1up.SetLineWeight(2);

plot line1dwn = if 1 > q then na else baseline - (spacing_factor * 1);
plot line2dwn = if 2 > q then na else baseline - (spacing_factor * 2);
plot line3dwn = if 3 > q then na else baseline - (spacing_factor * 3);
plot line4dwn = if 4 > q then na else baseline - (spacing_factor * 4);
plot line5dwn = if 5 > q then na else baseline - (spacing_factor * 5);

line5dwn.SetDefaultColor(Color.LIME);
line5dwn.SetStyle(Curve.MEDIUM_DASH);
line5dwn.SetLineWeight(2);

line4dwn.SetDefaultColor(Color.LIME);
line4dwn.SetStyle(Curve.MEDIUM_DASH);
line4dwn.SetLineWeight(2);

line3dwn.SetDefaultColor(Color.LIME);
line3dwn.SetStyle(Curve.MEDIUM_DASH);
line3dwn.SetLineWeight(2);

line2dwn.SetDefaultColor(Color.LIME);
line2dwn.SetStyle(Curve.MEDIUM_DASH);
line2dwn.SetLineWeight(2);

line1dwn.SetDefaultColor(Color.LIME);
line1dwn.SetStyle(Curve.MEDIUM_DASH);
line1dwn.SetLineWeight(2);

#
 
you will need a plot function for each line you want. fold loops can repeat a formula x times, but it returns 1 number value. they can't include a plot. you can't have a loop repeat a plot many times.

below are ideas and formulas, may not be exact thinkscript codes.
the below formulas create instantaneous values.
you will have to search and find a study code that plots price line levels.

so you may want to do something like draw 3 lines above the current price, and 3 lines below it.
you could create a formula to find a multiple of 10, that is closest to the current price. call it baseline.

def basefactor = round( close /10, 0);
def baseline = basefactor * 10;

then add 3 numbers to it for lines above and subtract 3 numbers, for lines below.

def line1up = baseline + (10 + your number) ;
def line2up = baseline + (20 + your number) ;
def line3up = baseline + (30 + your number) ;

def line1dwn = baseline - (10 + your number) ;
def line2dwn = baseline - (20 + your number) ;
def line3dwn = baseline - (30 + your number);

then apply horizontal line formulas ( highestall(.... or whatever ) to each of the 7 values above.

here is an example code that draws a horizontal line.
https://usethinkscript.com/threads/how-to-plot-horizontal-line-in-thinkscript.836/#post-6832
is there a way to change the B value to pick the daily open instead of current close price? I want to be able to draw lines above and below the daily open automatically. if possible be able to enter individual value to each line for example:

aboveline2 = +15
aboveline1 = +10
dailyopen price = 1
belowline1 = -5
belowline2 =-25

sorry for asking to custom this. this is actually a great study indicator.
 
is there a way to change the B value to pick the daily open instead of current close price? I want to be able to draw lines above and below the daily open automatically. if possible be able to enter individual value to each line for example:

aboveline2 = +15
aboveline1 = +10
dailyopen price = 1
belowline1 = -5
belowline2 =-25

sorry for asking to custom this. this is actually a great study indicator.

no need to be sorry, ask your questions.

here is a study that draws a horizontal line from the open of the day.
then draws up to 4 other lines, based on offset numbers.
if a number is 0, then no line is drawn.

Code:
# lines_from_dayopen

#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-122881
#post7
#is there a way to change the B value to pick the daily open instead of current close price? I want to be able to draw lines above and below the daily open automatically. if possible be able to enter individual value to each line for example:

#aboveline2 = +15
#aboveline1 = +10
#dailyopen price = 1
#belowline1 = -5
#belowline2 =-25


def na = double.nan;

input start = 0930;
def dayopen = if secondstillTime(start) == 0 then open else dayopen[1];

input aboveline2 = 15.0;
input aboveline1 = 10.0;
#dailyopen price = 1
input belowline1 = -5.0;
input belowline2 = -25.0;


plot zup2 = if aboveline2 == 0 then na else dayopen + aboveline2;
plot zup1 = if aboveline1 == 0 then na else dayopen + aboveline1;
plot z0 = dayopen;
plot zdwn1 = if belowline1 == 0 then na else dayopen + belowline1;
plot zdwn2 = if belowline2 == 0 then na else dayopen + belowline2;

zup2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup2.SetDefaultColor(Color.LIME);
zup2.SetStyle(Curve.MEDIUM_DASH);
zup2.SetLineWeight(2);
zup1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup1.SetDefaultColor(Color.LIME);
zup1.SetStyle(Curve.MEDIUM_DASH);
zup1.SetLineWeight(2);

z0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z0.SetDefaultColor(Color.magenta);
z0.SetStyle(Curve.short_DASH);
z0.SetLineWeight(2);

zdwn1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn1.SetDefaultColor(Color.LIME);
zdwn1.SetStyle(Curve.MEDIUM_DASH);
zdwn1.SetLineWeight(2);
zdwn2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn2.SetDefaultColor(Color.LIME);
zdwn2.SetStyle(Curve.MEDIUM_DASH);
zdwn2.SetLineWeight(2);
#
 
no need to be sorry, ask your questions.

here is a study that draws a horizontal line from the open of the day.
then draws up to 4 other lines, based on offset numbers.
if a number is 0, then no line is drawn.

Code:
# lines_from_dayopen

#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-122881
#post7
#is there a way to change the B value to pick the daily open instead of current close price? I want to be able to draw lines above and below the daily open automatically. if possible be able to enter individual value to each line for example:

#aboveline2 = +15
#aboveline1 = +10
#dailyopen price = 1
#belowline1 = -5
#belowline2 =-25


def na = double.nan;

input start = 0930;
def dayopen = if secondstillTime(start) == 0 then open else dayopen[1];

input aboveline2 = 15.0;
input aboveline1 = 10.0;
#dailyopen price = 1
input belowline1 = -5.0;
input belowline2 = -25.0;


plot zup2 = if aboveline2 == 0 then na else dayopen + aboveline2;
plot zup1 = if aboveline1 == 0 then na else dayopen + aboveline1;
plot z0 = dayopen;
plot zdwn1 = if belowline1 == 0 then na else dayopen + belowline1;
plot zdwn2 = if belowline2 == 0 then na else dayopen + belowline2;

zup2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup2.SetDefaultColor(Color.LIME);
zup2.SetStyle(Curve.MEDIUM_DASH);
zup2.SetLineWeight(2);
zup1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup1.SetDefaultColor(Color.LIME);
zup1.SetStyle(Curve.MEDIUM_DASH);
zup1.SetLineWeight(2);

z0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z0.SetDefaultColor(Color.magenta);
z0.SetStyle(Curve.short_DASH);
z0.SetLineWeight(2);

zdwn1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn1.SetDefaultColor(Color.LIME);
zdwn1.SetStyle(Curve.MEDIUM_DASH);
zdwn1.SetLineWeight(2);
zdwn2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn2.SetDefaultColor(Color.LIME);
zdwn2.SetStyle(Curve.MEDIUM_DASH);
zdwn2.SetLineWeight(2);
#
is there a way to make this work on mobile?
 
no need to be sorry, ask your questions.

here is a study that draws a horizontal line from the open of the day.
then draws up to 4 other lines, based on offset numbers.
if a number is 0, then no line is drawn.

Code:
# lines_from_dayopen

#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-122881
#post7
#is there a way to change the B value to pick the daily open instead of current close price? I want to be able to draw lines above and below the daily open automatically. if possible be able to enter individual value to each line for example:

#aboveline2 = +15
#aboveline1 = +10
#dailyopen price = 1
#belowline1 = -5
#belowline2 =-25


def na = double.nan;

input start = 0930;
def dayopen = if secondstillTime(start) == 0 then open else dayopen[1];

input aboveline2 = 15.0;
input aboveline1 = 10.0;
#dailyopen price = 1
input belowline1 = -5.0;
input belowline2 = -25.0;


plot zup2 = if aboveline2 == 0 then na else dayopen + aboveline2;
plot zup1 = if aboveline1 == 0 then na else dayopen + aboveline1;
plot z0 = dayopen;
plot zdwn1 = if belowline1 == 0 then na else dayopen + belowline1;
plot zdwn2 = if belowline2 == 0 then na else dayopen + belowline2;

zup2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup2.SetDefaultColor(Color.LIME);
zup2.SetStyle(Curve.MEDIUM_DASH);
zup2.SetLineWeight(2);
zup1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup1.SetDefaultColor(Color.LIME);
zup1.SetStyle(Curve.MEDIUM_DASH);
zup1.SetLineWeight(2);

z0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z0.SetDefaultColor(Color.magenta);
z0.SetStyle(Curve.short_DASH);
z0.SetLineWeight(2);

zdwn1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn1.SetDefaultColor(Color.LIME);
zdwn1.SetStyle(Curve.MEDIUM_DASH);
zdwn1.SetLineWeight(2);
zdwn2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn2.SetDefaultColor(Color.LIME);
zdwn2.SetStyle(Curve.MEDIUM_DASH);
zdwn2.SetLineWeight(2);
#
can this be done in 2 time frames, 9:30 to 1:00 then it resets again from 1:00 to close of market?
 
can this be done in 2 time frames, 9:30 to 1:00 then it resets again from 1:00 to close of market?

yes
here is a version that draws lines during 2 periods of time

Code:
# lines_from_price2

#ver2
#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-133393
#can this be done in 2 time frames, 9:30 to 1:00 then it resets again from 1:00 to close of market?

def na = double.nan;

input period1_start = 0930;
input period1_end = 1300;
input period2_start = 1300;
input period2_end = 1600;

def isper1 = (secondsfromTime(period1_start) >= 0 and secondstillTime(period1_end) > 0);
def isper2 = (secondsfromTime(period2_start) >= 0 and secondstillTime(period2_end) > 0);


input price = open;
def per1 = if secondstillTime(period1_start) == 0 then price
 else if isper1 then per1[1]
 else na;

def per2 = if secondstillTime(period2_start) == 0 then price
 else if isper2 then per2[1]
 else na;


input aboveline2 = 15.0;
input aboveline1 = 10.0;
#dailyopen price = 1
input belowline1 = -5.0;
input belowline2 = -25.0;

def baseline = if isper1 then per1
else if isper2 then per2
else na;


plot zup2 = if aboveline2 == 0 then na else baseline + aboveline2;
plot zup1 = if aboveline1 == 0 then na else baseline + aboveline1;
plot z0 = baseline;
plot zdwn1 = if belowline1 == 0 then na else baseline + belowline1;
plot zdwn2 = if belowline2 == 0 then na else baseline + belowline2;

zup2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup2.SetDefaultColor(Color.LIME);
zup2.SetStyle(Curve.MEDIUM_DASH);
zup2.SetLineWeight(2);
zup1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup1.SetDefaultColor(Color.LIME);
zup1.SetStyle(Curve.MEDIUM_DASH);
zup1.SetLineWeight(2);

z0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z0.SetDefaultColor(Color.magenta);
z0.SetStyle(Curve.short_DASH);
z0.SetLineWeight(2);

zdwn1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn1.SetDefaultColor(Color.LIME);
zdwn1.SetStyle(Curve.MEDIUM_DASH);
zdwn1.SetLineWeight(2);
zdwn2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn2.SetDefaultColor(Color.LIME);
zdwn2.SetStyle(Curve.MEDIUM_DASH);
zdwn2.SetLineWeight(2);
#
 
yes
here is a version that draws lines during 2 periods of time

Code:
# lines_from_price2

#ver2
#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-133393
#can this be done in 2 time frames, 9:30 to 1:00 then it resets again from 1:00 to close of market?

def na = double.nan;

input period1_start = 0930;
input period1_end = 1300;
input period2_start = 1300;
input period2_end = 1600;

def isper1 = (secondsfromTime(period1_start) >= 0 and secondstillTime(period1_end) > 0);
def isper2 = (secondsfromTime(period2_start) >= 0 and secondstillTime(period2_end) > 0);


input price = open;
def per1 = if secondstillTime(period1_start) == 0 then price
 else if isper1 then per1[1]
 else na;

def per2 = if secondstillTime(period2_start) == 0 then price
 else if isper2 then per2[1]
 else na;


input aboveline2 = 15.0;
input aboveline1 = 10.0;
#dailyopen price = 1
input belowline1 = -5.0;
input belowline2 = -25.0;

def baseline = if isper1 then per1
else if isper2 then per2
else na;


plot zup2 = if aboveline2 == 0 then na else baseline + aboveline2;
plot zup1 = if aboveline1 == 0 then na else baseline + aboveline1;
plot z0 = baseline;
plot zdwn1 = if belowline1 == 0 then na else baseline + belowline1;
plot zdwn2 = if belowline2 == 0 then na else baseline + belowline2;

zup2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup2.SetDefaultColor(Color.LIME);
zup2.SetStyle(Curve.MEDIUM_DASH);
zup2.SetLineWeight(2);
zup1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup1.SetDefaultColor(Color.LIME);
zup1.SetStyle(Curve.MEDIUM_DASH);
zup1.SetLineWeight(2);

z0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z0.SetDefaultColor(Color.magenta);
z0.SetStyle(Curve.short_DASH);
z0.SetLineWeight(2);

zdwn1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn1.SetDefaultColor(Color.LIME);
zdwn1.SetStyle(Curve.MEDIUM_DASH);
zdwn1.SetLineWeight(2);
zdwn2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn2.SetDefaultColor(Color.LIME);
zdwn2.SetStyle(Curve.MEDIUM_DASH);
zdwn2.SetLineWeight(2);
#
Thank you
 
no need to be sorry, ask your questions.

here is a study that draws a horizontal line from the open of the day.
then draws up to 4 other lines, based on offset numbers.
if a number is 0, then no line is drawn.

Code:
# lines_from_dayopen

#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-122881
#post7
#is there a way to change the B value to pick the daily open instead of current close price? I want to be able to draw lines above and below the daily open automatically. if possible be able to enter individual value to each line for example:

#aboveline2 = +15
#aboveline1 = +10
#dailyopen price = 1
#belowline1 = -5
#belowline2 =-25


def na = double.nan;

input start = 0930;
def dayopen = if secondstillTime(start) == 0 then open else dayopen[1];

input aboveline2 = 15.0;
input aboveline1 = 10.0;
#dailyopen price = 1
input belowline1 = -5.0;
input belowline2 = -25.0;


plot zup2 = if aboveline2 == 0 then na else dayopen + aboveline2;
plot zup1 = if aboveline1 == 0 then na else dayopen + aboveline1;
plot z0 = dayopen;
plot zdwn1 = if belowline1 == 0 then na else dayopen + belowline1;
plot zdwn2 = if belowline2 == 0 then na else dayopen + belowline2;

zup2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup2.SetDefaultColor(Color.LIME);
zup2.SetStyle(Curve.MEDIUM_DASH);
zup2.SetLineWeight(2);
zup1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup1.SetDefaultColor(Color.LIME);
zup1.SetStyle(Curve.MEDIUM_DASH);
zup1.SetLineWeight(2);

z0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z0.SetDefaultColor(Color.magenta);
z0.SetStyle(Curve.short_DASH);
z0.SetLineWeight(2);

zdwn1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn1.SetDefaultColor(Color.LIME);
zdwn1.SetStyle(Curve.MEDIUM_DASH);
zdwn1.SetLineWeight(2);
zdwn2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn2.SetDefaultColor(Color.LIME);
zdwn2.SetStyle(Curve.MEDIUM_DASH);
zdwn2.SetLineWeight(2);
#
i love your horizontal lines ! can you ,alter your script to just draw a line every 100 points??ty in advance
 
yes
here is a version that draws lines during 2 periods of time

Code:
# lines_from_price2

#ver2
#https://usethinkscript.com/threads/how-to-plot-horizontal-lines-at-price-levels-where-the-price-ends-with-a-certain-number.7692/#post-133393
#can this be done in 2 time frames, 9:30 to 1:00 then it resets again from 1:00 to close of market?

def na = double.nan;

input period1_start = 0930;
input period1_end = 1300;
input period2_start = 1300;
input period2_end = 1600;

def isper1 = (secondsfromTime(period1_start) >= 0 and secondstillTime(period1_end) > 0);
def isper2 = (secondsfromTime(period2_start) >= 0 and secondstillTime(period2_end) > 0);


input price = open;
def per1 = if secondstillTime(period1_start) == 0 then price
 else if isper1 then per1[1]
 else na;

def per2 = if secondstillTime(period2_start) == 0 then price
 else if isper2 then per2[1]
 else na;


input aboveline2 = 15.0;
input aboveline1 = 10.0;
#dailyopen price = 1
input belowline1 = -5.0;
input belowline2 = -25.0;

def baseline = if isper1 then per1
else if isper2 then per2
else na;


plot zup2 = if aboveline2 == 0 then na else baseline + aboveline2;
plot zup1 = if aboveline1 == 0 then na else baseline + aboveline1;
plot z0 = baseline;
plot zdwn1 = if belowline1 == 0 then na else baseline + belowline1;
plot zdwn2 = if belowline2 == 0 then na else baseline + belowline2;

zup2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup2.SetDefaultColor(Color.LIME);
zup2.SetStyle(Curve.MEDIUM_DASH);
zup2.SetLineWeight(2);
zup1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zup1.SetDefaultColor(Color.LIME);
zup1.SetStyle(Curve.MEDIUM_DASH);
zup1.SetLineWeight(2);

z0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z0.SetDefaultColor(Color.magenta);
z0.SetStyle(Curve.short_DASH);
z0.SetLineWeight(2);

zdwn1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn1.SetDefaultColor(Color.LIME);
zdwn1.SetStyle(Curve.MEDIUM_DASH);
zdwn1.SetLineWeight(2);
zdwn2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdwn2.SetDefaultColor(Color.LIME);
zdwn2.SetStyle(Curve.MEDIUM_DASH);
zdwn2.SetLineWeight(2);
#
Great work. I was wondering if there is a way to draw horizontal lines up and down to infinity or a really high amount from a number I enter. For instance let's say I enter 100 and I wanted it to draw a line every ten pts up and down from the forever is that possible? I really appreciate your help.
 
ι don't know if this the right place to post a simple huge stupid script that draws 50 lines btw 2 prices by a flexible increment .here it is :
# Inputs for the start and end levels and interval
input startLevel = 17000;
input endLevel = 22000;
input interval = 100;

# Calculate the number of lines to be drawn
def numberOfLines = (endLevel - startLevel) / interval;

# Plot horizontal lines at each interval
plot line1 = if startLevel + interval * 0 <= endLevel then startLevel + interval * 0 else Double.NaN;
plot line2 = if startLevel + interval * 1 <= endLevel then startLevel + interval * 1 else Double.NaN;
plot line3 = if startLevel + interval * 2 <= endLevel then startLevel + interval * 2 else Double.NaN;
plot line4 = if startLevel + interval * 3 <= endLevel then startLevel + interval * 3 else Double.NaN;
plot line5 = if startLevel + interval * 4 <= endLevel then startLevel + interval * 4 else Double.NaN;
plot line6 = if startLevel + interval * 5 <= endLevel then startLevel + interval * 5 else Double.NaN;
plot line7 = if startLevel + interval * 6 <= endLevel then startLevel + interval * 6 else Double.NaN;
plot line8 = if startLevel + interval * 7 <= endLevel then startLevel + interval * 7 else Double.NaN;
plot line9 = if startLevel + interval * 8 <= endLevel then startLevel + interval * 8 else Double.NaN;
plot line10 = if startLevel + interval * 9 <= endLevel then startLevel + interval * 9 else Double.NaN;
plot line11 = if startLevel + interval * 10 <= endLevel then startLevel + interval * 10 else Double.NaN;
plot line12 = if startLevel + interval * 11 <= endLevel then startLevel + interval * 11 else Double.NaN;
plot line13 = if startLevel + interval * 12 <= endLevel then startLevel + interval * 12 else Double.NaN;
plot line14 = if startLevel + interval * 13 <= endLevel then startLevel + interval * 13 else Double.NaN;
plot line15 = if startLevel + interval * 14 <= endLevel then startLevel + interval * 14 else Double.NaN;
plot line16 = if startLevel + interval * 15 <= endLevel then startLevel + interval * 15 else Double.NaN;
plot line17 = if startLevel + interval * 16 <= endLevel then startLevel + interval * 16 else Double.NaN;
plot line18 = if startLevel + interval * 17 <= endLevel then startLevel + interval * 17 else Double.NaN;
plot line19 = if startLevel + interval * 18 <= endLevel then startLevel + interval * 18 else Double.NaN;
plot line20 = if startLevel + interval * 19 <= endLevel then startLevel + interval * 19 else Double.NaN;
plot line21 = if startLevel + interval * 20 <= endLevel then startLevel + interval * 20 else Double.NaN;
plot line22 = if startLevel + interval * 21 <= endLevel then startLevel + interval * 21 else Double.NaN;
plot line23 = if startLevel + interval * 22 <= endLevel then startLevel + interval * 22 else Double.NaN;
plot line24 = if startLevel + interval * 23 <= endLevel then startLevel + interval * 23 else Double.NaN;
plot line25 = if startLevel + interval * 24 <= endLevel then startLevel + interval * 24 else Double.NaN;
plot line26 = if startLevel + interval * 25 <= endLevel then startLevel + interval * 25 else Double.NaN;
plot line27 = if startLevel + interval * 26 <= endLevel then startLevel + interval * 26 else Double.NaN;
plot line28 = if startLevel + interval * 27 <= endLevel then startLevel + interval * 27 else Double.NaN;
plot line29 = if startLevel + interval * 28 <= endLevel then startLevel + interval * 28 else Double.NaN;
plot line30 = if startLevel + interval * 29 <= endLevel then startLevel + interval * 29 else Double.NaN;
plot line31 = if startLevel + interval * 30 <= endLevel then startLevel + interval * 30 else Double.NaN;
plot line32 = if startLevel + interval * 31 <= endLevel then startLevel + interval * 31 else Double.NaN;
plot line33 = if startLevel + interval * 32 <= endLevel then startLevel + interval * 32 else Double.NaN;
plot line34 = if startLevel + interval * 33 <= endLevel then startLevel + interval * 33 else Double.NaN;
plot line35 = if startLevel + interval * 34 <= endLevel then startLevel + interval * 34 else Double.NaN;
plot line36 = if startLevel + interval * 35 <= endLevel then startLevel + interval * 35 else Double.NaN;
plot line37 = if startLevel + interval * 36 <= endLevel then startLevel + interval * 36 else Double.NaN;
plot line38 = if startLevel + interval * 37 <= endLevel then startLevel + interval * 37 else Double.NaN;
plot line39 = if startLevel + interval * 38 <= endLevel then startLevel + interval * 38 else Double.NaN;
plot line40 = if startLevel + interval * 39 <= endLevel then startLevel + interval * 39 else Double.NaN;
plot line41 = if startLevel + interval * 40 <= endLevel then startLevel + interval * 40 else Double.NaN;
plot line42 = if startLevel + interval * 41 <= endLevel then startLevel + interval * 41 else Double.NaN;
plot line43 = if startLevel + interval * 42 <= endLevel then startLevel + interval * 42 else Double.NaN;
plot line44 = if startLevel + interval * 43 <= endLevel then startLevel + interval * 43 else Double.NaN;
plot line45 = if startLevel + interval * 44 <= endLevel then startLevel + interval * 44 else Double.NaN;
plot line46 = if startLevel + interval * 45 <= endLevel then startLevel + interval * 45 else Double.NaN;
plot line47 = if startLevel + interval * 46 <= endLevel then startLevel + interval * 46 else Double.NaN;
plot line48 = if startLevel + interval * 47 <= endLevel then startLevel + interval * 47 else Double.NaN;
plot line49 = if startLevel + interval * 48 <= endLevel then startLevel + interval * 48 else Double.NaN;
plot line50 = if startLevel + interval * 49 <= endLevel then startLevel + interval * 49 else Double.NaN;

# Set the style for each line to solid
line1.SetDefaultColor(Color.GRAY);
line1.SetStyle(Curve.FIRM); # Use Curve.FIRM for solid lines
line2.SetDefaultColor(Color.GRAY);
line2.SetStyle(Curve.FIRM);
line3.SetDefaultColor(Color.GRAY);
line3.SetStyle(Curve.FIRM);
line4.SetDefaultColor(Color.GRAY);
line4.SetStyle(Curve.FIRM);
line5.SetDefaultColor(Color.GRAY);
line5.SetStyle(Curve.FIRM);
line6.SetDefaultColor(Color.GRAY);
line6.SetStyle(Curve.FIRM);
line7.SetDefaultColor(Color.GRAY);
line7.SetStyle(Curve.FIRM);
line8.SetDefaultColor(Color.GRAY);
line8.SetStyle(Curve.FIRM);
line9.SetDefaultColor(Color.GRAY);
line9.SetStyle(Curve.FIRM);
line10.SetDefaultColor(Color.GRAY);
line10.SetStyle(Curve.FIRM);
line11.SetDefaultColor(Color.GRAY);
line11.SetStyle(Curve.FIRM);
line12.SetDefaultColor(Color.GRAY);
line12.SetStyle(Curve.FIRM);
line13.SetDefaultColor(Color.GRAY);
line13.SetStyle(Curve.FIRM);
line14.SetDefaultColor(Color.GRAY);
line14.SetStyle(Curve.FIRM);
line15.SetDefaultColor(Color.GRAY);
line15.SetStyle(Curve.FIRM);
line16.SetDefaultColor(Color.GRAY);
line16.SetStyle(Curve.FIRM);
line17.SetDefaultColor(Color.GRAY);
line17.SetStyle(Curve.FIRM);
line18.SetDefaultColor(Color.GRAY);
line18.SetStyle(Curve.FIRM);
line19.SetDefaultColor(Color.GRAY);
line19.SetStyle(Curve.FIRM);
line20.SetDefaultColor(Color.GRAY);
line20.SetStyle(Curve.FIRM);
line21.SetDefaultColor(Color.GRAY);
line21.SetStyle(Curve.FIRM);
line22.SetDefaultColor(Color.GRAY);
line22.SetStyle(Curve.FIRM);
line23.SetDefaultColor(Color.GRAY);
line23.SetStyle(Curve.FIRM);
line24.SetDefaultColor(Color.GRAY);
line24.SetStyle(Curve.FIRM);
line25.SetDefaultColor(Color.GRAY);
line25.SetStyle(Curve.FIRM);
line26.SetDefaultColor(Color.GRAY);
line26.SetStyle(Curve.FIRM);
line27.SetDefaultColor(Color.GRAY);
line27.SetStyle(Curve.FIRM);
line28.SetDefaultColor(Color.GRAY);
line28.SetStyle(Curve.FIRM);
line29.SetDefaultColor(Color.GRAY);
line29.SetStyle(Curve.FIRM);
line30.SetDefaultColor(Color.GRAY);
line30.SetStyle(Curve.FIRM);
line31.SetDefaultColor(Color.GRAY);
line31.SetStyle(Curve.FIRM);
line32.SetDefaultColor(Color.GRAY);
line32.SetStyle(Curve.FIRM);
line33.SetDefaultColor(Color.GRAY);
line33.SetStyle(Curve.FIRM);
line34.SetDefaultColor(Color.GRAY);
line34.SetStyle(Curve.FIRM);
line35.SetDefaultColor(Color.GRAY);
line35.SetStyle(Curve.FIRM);
line36.SetDefaultColor(Color.GRAY);
line36.SetStyle(Curve.FIRM);
line37.SetDefaultColor(Color.GRAY);
line37.SetStyle(Curve.FIRM);
line38.SetDefaultColor(Color.GRAY);
line38.SetStyle(Curve.FIRM);
line39.SetDefaultColor(Color.GRAY);
line39.SetStyle(Curve.FIRM);
line40.SetDefaultColor(Color.GRAY);
line40.SetStyle(Curve.FIRM);
line41.SetDefaultColor(Color.GRAY);
line41.SetStyle(Curve.FIRM);
line42.SetDefaultColor(Color.GRAY);
line42.SetStyle(Curve.FIRM);
line43.SetDefaultColor(Color.GRAY);
line43.SetStyle(Curve.FIRM);
line44.SetDefaultColor(Color.GRAY);
line44.SetStyle(Curve.FIRM);
line45.SetDefaultColor(Color.GRAY);
line45.SetStyle(Curve.FIRM);
line46.SetDefaultColor(Color.GRAY);
line46.SetStyle(Curve.FIRM);
line47.SetDefaultColor(Color.GRAY);
line47.SetStyle(Curve.FIRM);
line48.SetDefaultColor(Color.GRAY);
line48.SetStyle(Curve.FIRM);
line49.SetDefaultColor(Color.GRAY);
line49.SetStyle(Curve.FIRM);
line50.SetDefaultColor(Color.GRAY);
line50.SetStyle(Curve.FIRM);
 
I want to draw 2 horizontal lines across my charts (for daily and weekly views) where the high horizontal line is defined as the high of the first trading day of any week (obviously this is usually Monday unless a holiday week) and the low horizontal line is the low of the first trading day of the week. So these horizontal lines will change each week as new First Trading Day of the Week Highs and lows change. I would like the lines to persist on both daily and weekly charts.
 
Great work. I was wondering if there is a way to draw horizontal lines up and down to infinity or a really high amount from a number I enter. For instance let's say I enter 100 and I wanted it to draw a line every ten pts up and down from the forever is that possible? I really appreciate your help.

yes that is possible, but
you can't use plot within a loop,
so you need a plot statement for every line you want on a bar.
if you want 100 lines going over 1 bar, you need 100 plot statements and 100 sets of variables and formulas to support the plots. very tedious.
i'm not going to spend hours making that. you can learn thinkscript and modify my code in post #5
https://usethinkscript.com/threads/...-ends-with-a-certain-number.7692/#post-107271

or try post 16 code. maybe that will work for you
 
I want to draw 2 horizontal lines across my charts (for daily and weekly views) where the high horizontal line is defined as the high of the first trading day of any week (obviously this is usually Monday unless a holiday week) and the low horizontal line is the low of the first trading day of the week. So these horizontal lines will change each week as new First Trading Day of the Week Highs and lows change. I would like the lines to persist on both daily and weekly charts.

This seems to work as you want for daily, however Monday is not available on weekly.

Screenshot 2024-08-05 095144.jpg
Code:
input show_last_only = no;
def start_day_week   = if GetWeek() != GetWeek()[1]
                       then if GetDayOfWeek(GetYYYYMMDD()) == 1
                            then 1
                            else 2
                       else start_day_week[1] ;
def h   = if GetDayOfWeek(GetYYYYMMDD()) == start_day_week then high(period = AggregationPeriod.DAY) else h[1];
def l   = if GetDayOfWeek(GetYYYYMMDD()) == start_day_week then low(period = AggregationPeriod.DAY) else l[1];
plot hh = if show_last_only and GetWeek() != GetLastWeek() then Double.NaN else h;
plot ll = if show_last_only and GetWeek() != GetLastWeek() then Double.NaN else l;
 
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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