Plot Horizontal Lines in Lower Window

Pilotone

New member
I am trying to plot six lines on a lower window at "0".
Each line would extend from a specific time and end at a specific time.
They would occur daily but only for the current day. In other words not display for every day simultaneously.
Ideally each line would have it's own color.
For Example London 9 pm - 1 am. Note in this case it extends into the next day.
The other lines are withing the same day.
Sorry, image would not post.

Thanks much
 
Solution
here is another way, using a sub script , reusing the same code.
i used constants for parameters in the 6 plots commands at the end.
you can replace them with variables.
i used different price levels to make it easier to see the separate lines.

Code:
# lowerlines_02

declare lower;

script drawline {
  input start = 0;
  input end = 0;
  input pricelevel = 0;
  input color = 0;
  input thick = 0;

# line 1
# define a time period
#input start1 = 1000;
#input end1 = 1100;
# is current bar during the desired time period?
def period1 = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;
def istoday = if GetLastDay() == GetDay() then 1 else 0;

# combine those 2 rules into 1 condition, true when both are true
def line1 =...
for each line, there will be 2 time conditions.
1. is the current bar in the desired time period
2. is it today.
here is an example to draw a line within a time period, on just the current day.

Code:
# lowerlines_01

declare lower;

def na = Double.NaN;

# line 1
# define a time period
input start1 = 1000;
input end1 = 1100;
# is current bar during the desired time period?
def period1 = if SecondsFromTime(start1) >= 0 and SecondsTillTime(end1) > 0 then 1 else 0;

def istoday = if GetLastDay() == GetDay() then 1 else 0;

# combine those 2 rules into 1 condition, true when both are true
def line1 = (period1 and istoday);

plot z1 = if line1 then 0 else na;
z1.SetDefaultColor(color.red);
z1.SetStyle(Curve.MEDIUM_DASH);
# a number 1-5
z1.setlineweight(2);
z1.hidebubble();
#

just copy this 6 times and change the variables.
this uses specific times to define a period.

there is another way, but i'll start with the simple way
 

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

here is another way, using a sub script , reusing the same code.
i used constants for parameters in the 6 plots commands at the end.
you can replace them with variables.
i used different price levels to make it easier to see the separate lines.

Code:
# lowerlines_02

declare lower;

script drawline {
  input start = 0;
  input end = 0;
  input pricelevel = 0;
  input color = 0;
  input thick = 0;

# line 1
# define a time period
#input start1 = 1000;
#input end1 = 1100;
# is current bar during the desired time period?
def period1 = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;
def istoday = if GetLastDay() == GetDay() then 1 else 0;

# combine those 2 rules into 1 condition, true when both are true
def line1 = (period1 and istoday);

plot z1 = if line1 then pricelevel else Double.NaN;
#z1.SetDefaultColor(color.red);
z1.SetDefaultColor(getcolor(color));
#z1.SetStyle(Curve.MEDIUM_DASH);
# a number 1-5
z1.setlineweight(thick);
z1.hidebubble();
}

#  start , end, price level , color# (0-9) , thickness (1-5)

plot a = drawline(0900, 1100, 0, 1, 2);
plot b = drawline(1000, 1300, 1, 2, 1);
plot c = drawline(0930, 1600, 2, 3, 4);
plot d = drawline(1130, 1300, 3, 4, 1);
plot e = drawline(1300, 1400, 4, 5, 2);
plot f = drawline(1100, 1400, 5, 6, 3);
#

nXJAuQo.jpg
 
Solution
@halcyonguy, thanks for sharing the code! It's really sophisticated and I have learned something from your code.

I would like share one thing about showing horizontal lines correctly in the lower position, just in case some people are searching for the answer.

I was trying to show $Tick and $ADD in the lower windows with some horizontal lines. I prefer showing bars instead of lines, but it seems the "ChartType" function has been deprecated, so I cannot code everything in one go. Then I came up with two solutions:

1: Drawing price levels manually.
Drawing manually give me fixed lines, which is good. But when I changed to other product symbols, price levels disappeared. I don't want to draw these lines every time I change symbols.

2: Putting Comparison and the code of Horizontal Lines together.
This sounds simple. However, to my surprise, when I do this, the scale on the right-hand side sometimes became percentage and and sometimes became numbers. That really drove me crazy! Finally, I found the solution: placing horizontal line code first and comparison second will make the scale show fixed numbers.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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