FAQ – How to Display Labels only at a specific time every day?

Quite often in TradingView, you might want to display labels at a specific time every day. It can be some information at day close, day open, premarket, etc. In this article, I will show you how you can exactly that.

If you’ll just use the label.new function as is it will simply plot labels for every bar:

//@version=4
study("My Script", overlay = true)

label.new(bar_index, high, tostring(close))

To display a label for a specific time you have to add an additional filter. You can use the time function with a session to execute something only for one bar a day. Check the following code:

t = time(timeframe.period, "1500-1501")
bgcolor(not na(t) ? color.green : na)

Here I’m using a session 1500-1501. This will return not NA value only for 1 bar with open at 15:00 every day. And it looks like that:

Using this function you can easily display labels only for this bar. Here is entire code for that:

//@version=4
study("My Script", overlay = true)

t = time(timeframe.period, "1500-1501")

if (not na(t))
    label.new(bar_index, high, tostring(close))

Here is the result:


Follow me on TradingView and YouTube.