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.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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