Horizontal Line @ Specific Time

RlyNotUrBroker

New member
Hello. I'm sure this is a basic question but I'm just getting into ThinkScript but I can't figure out for the life of me how to get a horizontal line to plot at the previous day close. what I have is as follows:

def lasttrade = close;
plot test = close;
def aggregation = aggregationPeriod.DAY;

it will plot a line at every close price for the chart timeframe I'm looking at, but I want it to plot only a horizontal line at the previous day close.
Basically I want it to look at only the previous candle and plot a horizontal line across the chart that marks the previous close
I've tried the painting strategy.HORIZONTAL but it gives me a syntax error and I don't know where to go with this anymore. any help is appreciated!
 
Last edited by a moderator:
@SleepyZ

I tried to use this code by updating the time with my needs but I could not figure out the extension for the 1:30 , I am looking the 1:30 candle to get extended to the next, if u could help me on that.

again Thank you so much


The code from https://usethinkscript.com/threads/horizontal-line-specific-time.7327/post-114857 that I think you used has the 'High' as the price to plot.
Based upon your request above, I modified that code to plot 2 lines from the times to the next day's same times.
Screenshot 2024-10-13 171908.jpg
Code:
#Horizontal_Lines_at_SelectTimes_to_next_day

input price = open;

input time1 = 0000;
input time2 = 1330;

input show_lines  = yes;
input show_labels = yes;

def na      = Double.NaN;

def sec1 = SecondsFromTime(time1);
def sec2 = SecondsFromTime(time2);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

def ln1     = if istime1 then price else ln1[1];
def ln2     = if istime2 then price else ln2[1];

plot line1  = if !show_lines then na else ln1;
plot line2  = if !show_lines then na else ln2;

line1.SetPaintingStrategy(PaintingStrategy.DASHES);
line2.SetPaintingStrategy(PaintingStrategy.DASHES);

addlabel(show_labels, "Time1: " + asprice(time1), line1.takeValueColor());
addlabel(show_labels, "Time2: " + asprice(time2), line2.takeValueColor());

#
 

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

The code from https://usethinkscript.com/threads/horizontal-line-specific-time.7327/post-114857 that I think you used has the 'High' as the price to plot.
Based upon your request above, I modified that code to plot 2 lines from the times to the next day's same times.

HI @SleepyZ Thanks for writing this script. This is what i am searching for. I selected two time frame (mid night open and market open).

1. After adding the script and when I move the charts left or right the lines are NOT locked to the candles and they look like floating. Can you please help to fix them?

2. Can you please add an option to show today lines only?

3. Can the lines stop at 4 PM EST (Line 1: mid night to 4 PM. Line 2: 9.30 AM to 4 PM)?

4. Can you please add bubble with price at open on the line?

Thanks for your support .


1757101916200.png
 
Last edited:
HI @SleepyZ Thanks for writing this script. This is what i am searching for. I selected two time frame (mid night open and market open).

1. After adding the script and when I move the charts left or right the lines are NOT locked to the candles and they look like floating. Can you please help to fix them?

2. Can you please add an option to show today lines only?

3. Can the lines stop at 4 PM EST (Line 1: mid night to 4 PM. Line 2: 9.30 AM to 4 PM)?

4. Can you please add bubble with price at open on the line?

Thanks for your support .


View attachment 25661

This should help do all that you want. Use the inputs to control what you want.
The image is shown using EST zone and midnight (0000) and 0930 starts ending at 1600
The lines are limited to the number input at number_lines_to_show and end at 1600.
Code:
#Horizontal_Lines_at_SelectTimes_to_endtime

input price = open;

input time1 = 0000;
input time2 = 0930;
input endtime = 1600;

input number_lines_to_show = 1;
input show_lines  = yes;
input show_labels = yes;

def na      = Double.NaN;

def sec1 = SecondsFromTime(time1);
def sec2 = SecondsFromTime(time2);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

def ln1     = if isTime1 then price else if SecondsFromTime(endtime) > 0 then na else ln1[1];
def ln2     = if isTime2 then price else if SecondsFromTime(endtime) > 0 then na else ln2[1];

def ln1count = if isTime1 then ln1count[1] + 1 else ln1count[1];
def ln1cond  = HighestAll(ln1count) - ln1count + 1;
def ln2count = if isTime2 then ln2count[1] + 1 else ln2count[1];
def ln2cond  = HighestAll(ln2count) - ln2count + 1;
#addchartBubble(1,low,ln1count+"\n"+ln1cond,color.yellow,no);

plot line1  = if !show_lines or ln1cond > number_lines_to_show then na else ln1;
plot line2  = if !show_lines or ln2cond > number_lines_to_show then na else ln2;

line1.SetPaintingStrategy(PaintingStrategy.DASHES);
line2.SetPaintingStrategy(PaintingStrategy.DASHES);

AddLabel(show_labels, "Time1: " + AsPrice(time1), line1.TakeValueColor());
AddLabel(show_labels, "Time2: " + AsPrice(time2), line2.TakeValueColor());

input show_bubbles = yes;
AddChartBubble(show_bubbles and isTime1 and ln1cond <= number_lines_to_show, price, price, line1.TakeValueColor());
AddChartBubble(show_bubbles and isTime2 and ln2cond <= number_lines_to_show, price, price, line2.TakeValueColor());

#
 
This should help do all that you want. Use the inputs to control what you want.
The image is shown using EST zone and midnight (0000) and 0930 starts ending at 1600
The lines are limited to the number input at number_lines_to_show and end at 1600.
Thank you @SleepyZ . Great.

One minor adjustment. Is it possible to move the bubble on right?
 
Thank you @SleepyZ . Great.

One minor adjustment. Is it possible to move the bubble on right?

The bubbles are movable and displayed now on the right
Code:
#Horizontal_Lines_at_SelectTimes_to_endtime

input price = open;

input time1 = 0000;
input time2 = 0930;
input endtime = 1600;

input number_lines_to_show = 1;
input show_lines  = yes;
input show_labels = yes;

def na      = Double.NaN;

def sec1 = SecondsFromTime(time1);
def sec2 = SecondsFromTime(time2);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

def ln1     = if isTime1 then price else if SecondsFromTime(endtime) > 0 then na else ln1[1];
def ln2     = if isTime2 then price else if SecondsFromTime(endtime) > 0 then na else ln2[1];

def ln1count = if isTime1 then ln1count[1] + 1 else ln1count[1];
def ln1cond  = HighestAll(ln1count) - ln1count + 1;
def ln2count = if isTime2 then ln2count[1] + 1 else ln2count[1];
def ln2cond  = HighestAll(ln2count) - ln2count + 1;
#addchartBubble(1,low,ln1count+"\n"+ln1cond,color.yellow,no);

plot line1  = if !show_lines or ln1cond > number_lines_to_show then na else ln1;
plot line2  = if !show_lines or ln2cond > number_lines_to_show then na else ln2;

line1.SetPaintingStrategy(PaintingStrategy.DASHES);
line2.SetPaintingStrategy(PaintingStrategy.DASHES);

AddLabel(show_labels, "Time1: " + AsPrice(time1), line1.TakeValueColor());
AddLabel(show_labels, "Time2: " + AsPrice(time2), line2.TakeValueColor());

input show_bubbles = yes;
input bubblemover  = 3;
def mover = !IsNaN(close[bubblemover + 1]) and IsNaN(close[bubblemover]);
AddChartBubble(show_bubbles and mover and ln1cond[bubblemover + 1] <= number_lines_to_show, line1[bubblemover + 1], ln1[bubblemover + 1], line1.TakeValueColor());
AddChartBubble(show_bubbles and mover and ln2cond[bubblemover + 1] <= number_lines_to_show, line2[bubblemover + 1], ln2[bubblemover + 1], line2.TakeValueColor());

#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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