Display Labels at Specific Times of Day

Amused to Death

New member
What would be the correct syntax for displaying different labels at specific times of day? Labels might indicate "premarket," "day open," "European close," etc. I've found scripts for drawing vertical lines at various times, but nothing for displaying labels instead.

Say I wanted to display labels representing various "zones," with each label remaining on an intraday chart until the next time zone is reached:

0000 to 0700 "Zone 1"
0700 to 0930 "Zone 2"
0930 to 1130 "Zone 3"
1130 to 1330 "Zone 4"
1330 to 1600 "Zone 5"
1600 to 2000 "Zone 6"
2000 to 2230 "Zone 7"
2230 to 0000 "Zone 8"

In this example, with all 24 hours in a day accounted for, there should never be a time when a "zone" label isn't being displayed on an intraday chart.

An (on/off) option to include vertical lines between each of these zones would be nice, but the labels are the primary focus.

I'm new to ThinkScript (and this forum — my first post!), so any/all help is appreciated!
 
Solution
What would be the correct syntax for displaying different labels at specific times of day? Labels might indicate "premarket," "day open," "European close," etc. I've found scripts for drawing vertical lines at various times, but nothing for displaying labels instead.

Say I wanted to display labels representing various "zones," with each label remaining on an intraday chart until the next time zone is reached:

0000 to 0700 "Zone 1"
0700 to 0930 "Zone 2"
0930 to 1130 "Zone 3"
1130 to 1330 "Zone 4"
1330 to 1600 "Zone 5"
1600 to 2000 "Zone 6"
2000 to 2230 "Zone 7"
2230 to 0000 "Zone 8"

In this example, with all 24 hours in a day accounted for, there should never be a time when a "zone" label isn't being displayed on an intraday...
What would be the correct syntax for displaying different labels at specific times of day? Labels might indicate "premarket," "day open," "European close," etc. I've found scripts for drawing vertical lines at various times, but nothing for displaying labels instead.

Say I wanted to display labels representing various "zones," with each label remaining on an intraday chart until the next time zone is reached:

0000 to 0700 "Zone 1"
0700 to 0930 "Zone 2"
0930 to 1130 "Zone 3"
1130 to 1330 "Zone 4"
1330 to 1600 "Zone 5"
1600 to 2000 "Zone 6"
2000 to 2230 "Zone 7"
2230 to 0000 "Zone 8"

In this example, with all 24 hours in a day accounted for, there should never be a time when a "zone" label isn't being displayed on an intraday chart.

An (on/off) option to include vertical lines between each of these zones would be nice, but the labels are the primary focus.

I'm new to ThinkScript (and this forum — my first post!), so any/all help is appreciated!

Try this

Ruby:
input showlabels = yes;

AddLabel(showlabels and SecondsFromTime(0000) >= 0 and SecondsTillTime(0700) > 0, "Zone 1", Color.WHITE);
AddLabel(showlabels and SecondsFromTime(0700) >= 0 and SecondsTillTime(0930) > 0, "Zone 2", Color.WHITE);
AddLabel(showlabels and SecondsFromTime(0930) >= 0 and SecondsTillTime(1130) > 0, "Zone 3", Color.WHITE);
AddLabel(showlabels and SecondsFromTime(1130) >= 0 and SecondsTillTime(1330) > 0, "Zone 4", Color.WHITE);
AddLabel(showlabels and SecondsFromTime(1330) >= 0 and SecondsTillTime(1600) > 0, "Zone 5", Color.WHITE);
AddLabel(showlabels and SecondsFromTime(1600) >= 0 and SecondsTillTime(2000) > 0, "Zone 6", Color.WHITE);
AddLabel(showlabels and SecondsFromTime(2000) >= 0 and SecondsTillTime(223) > 0, "Zone 7", Color.WHITE);
AddLabel(showlabels and SecondsFromTime(2230) >= 0 and SecondsTillTime(0000) > 0, "Zone 8", Color.WHITE);

input showverticals = yes;

AddVerticalLine(showverticals and SecondsFromTime(0000) == 0, "Zone 1", Color.WHITE);
AddVerticalLine(showverticals and SecondsFromTime(0700) == 0, "Zone 2", Color.WHITE);
AddVerticalLine(showverticals and SecondsFromTime(0930) == 0, "Zone 3", Color.WHITE);
AddVerticalLine(showverticals and SecondsFromTime(1130) == 0, "Zone 4", Color.WHITE);
AddVerticalLine(showverticals and SecondsFromTime(1330) == 0, "Zone 5", Color.WHITE);
AddVerticalLine(showverticals and SecondsFromTime(1600) == 0, "Zone 6", Color.WHITE);
AddVerticalLine(showverticals and SecondsFromTime(2000) == 0, "Zone 7", Color.WHITE);
AddVerticalLine(showverticals and SecondsFromTime(2230) == 0, "Zone 8", Color.WHITE);
 
Solution
Hello traders,

Is there a way to add a horizontal line starting from the times specified instead of a vertical?

I tried tweaking the above code as follows but no joy.

Any ideas?

-------------------------
input showhorizontals = yes;

AddHorizontalLine(showhorizontals and SecondsFromTime(0000) == 0, "Zone 1", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(0700) == 0, "Zone 2", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(0930) == 0, "Zone 3", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(1130) == 0, "Zone 4", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(1330) == 0, "Zone 5", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(1600) == 0, "Zone 6", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(2000) == 0, "Zone 7", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(2230) == 0, "Zone 8", Color.WHITE);
-------------------------

Error:
No such function: AddHorizontalLine at 5:1
No such function: AddHorizontalLine at 5:1
No such function: AddHorizontalLine at 6:1
No such function: AddHorizontalLine at 6:1
No such function: AddHorizontalLine at 7:1
No such function: AddHorizontalLine at 7:1
No such function: AddHorizontalLine at 8:1
No such function: AddHorizontalLine at 8:1
No such function: AddHorizontalLine at 9:1
No such function: AddHorizontalLine at 9:1
No such function: AddHorizontalLine at 10:1
No such function: AddHorizontalLine at 10:1
No such function: AddHorizontalLine at 3:1
 
Try this -

Python:
plot Z1= if showhorizontals and SecondsFromTime(0000) == 0 then close else Double.NaN;
Z1.SetPaintingStrategy(PaintingStrategy.DASHES);
Z1.AssignValueColor(Color.BLACK);
Z1.SetLineWeight(1);
Z1.HideBubble();
Z1.HideTitle();
 
Hello traders,

Is there a way to add a horizontal line starting from the times specified instead of a vertical?

I tried tweaking the above code as follows but no joy.

Any ideas?

-------------------------
input showhorizontals = yes;

AddHorizontalLine(showhorizontals and SecondsFromTime(0000) == 0, "Zone 1", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(0700) == 0, "Zone 2", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(0930) == 0, "Zone 3", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(1130) == 0, "Zone 4", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(1330) == 0, "Zone 5", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(1600) == 0, "Zone 6", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(2000) == 0, "Zone 7", Color.WHITE);
AddHorizontalLine(showhorizontals and SecondsFromTime(2230) == 0, "Zone 8", Color.WHITE);
-------------------------

Error:
No such function: AddHorizontalLine at 5:1
No such function: AddHorizontalLine at 5:1
No such function: AddHorizontalLine at 6:1
No such function: AddHorizontalLine at 6:1
No such function: AddHorizontalLine at 7:1
No such function: AddHorizontalLine at 7:1
No such function: AddHorizontalLine at 8:1
No such function: AddHorizontalLine at 8:1
No such function: AddHorizontalLine at 9:1
No such function: AddHorizontalLine at 9:1
No such function: AddHorizontalLine at 10:1
No such function: AddHorizontalLine at 10:1
No such function: AddHorizontalLine at 3:1

Here is another way using the script function, named x.
Fill in within the script x()
, differences between plots/lines, eg:
plot x1 = x(time = 0000, zone = 1, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
plot x2 = x(time = 0700, zone = 2, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
The image shows input showtodayonly = yes; ... If you select no, the other days will plot up to the next day's same line.
The chart bubbles will display on the last day and can be moved sideways at input bubblemover

Screenshot 2024-10-14 161406.jpg
Code:
script x {
    input time  = 0000;
    input zone  = 1;
    input price = close;
    input showhorizontals = yes;
    input showtodayonly   = yes;
    def ymd   = GetYYYYMMDD();
    def count = if !IsNaN(close) and ymd[1] != ymd then count[1] + 1 else count[1];
    def cond  = HighestAll(count) - count ;
    def line = if showtodayonly and cond > 1
then Double.NaN
else if showhorizontals and SecondsFromTime(time) == 0 and cond <= zone
then price
else line[1];

    plot xline = line;

}

input showhorizontals = yes;
input showtodayonly   = no;
input price           = close;
plot x1 = x(time = 0000, zone = 1, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
plot x2 = x(time = 0700, zone = 2, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
plot x3 = x(time = 0930, zone = 3, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
plot x4 = x(time = 1130, zone = 4, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
plot x5 = x(time = 1330, zone = 5, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
plot x6 = x(time = 1600, zone = 6, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
plot x7 = x(time = 2000, zone = 7, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);
plot x8 = x(time = 2230, zone = 8, price = price, showhorizontals = showhorizontals, showtodayonly = showtodayonly);

x1.SetPaintingStrategy(PaintingStrategy.DASHES);
x2.SetPaintingStrategy(PaintingStrategy.DASHES);
x3.SetPaintingStrategy(PaintingStrategy.DASHES);
x4.SetPaintingStrategy(PaintingStrategy.DASHES);
x5.SetPaintingStrategy(PaintingStrategy.DASHES);
x6.SetPaintingStrategy(PaintingStrategy.DASHES);
x7.SetPaintingStrategy(PaintingStrategy.DASHES);
x8.SetPaintingStrategy(PaintingStrategy.DASHES);

input showbubbles = yes;
input bubblemover = 5;
def mover = showbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]);
AddChartBubble(mover, x1[bubblemover], "Z1", x1.TakeValueColor());
AddChartBubble(mover, x2[bubblemover], "Z2", x2.TakeValueColor());
AddChartBubble(mover, x3[bubblemover], "Z3", x3.TakeValueColor());
AddChartBubble(mover, x4[bubblemover], "Z4", x4.TakeValueColor());
AddChartBubble(mover, x5[bubblemover], "Z5", x5.TakeValueColor());
AddChartBubble(mover, x6[bubblemover], "Z6", x6.TakeValueColor());
AddChartBubble(mover, x7[bubblemover], "Z7", x7.TakeValueColor());
AddChartBubble(mover, x8[bubblemover], "Z8", x8.TakeValueColor());

#end code
 
Last edited:

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
475 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