Pinescripter
Pine Script Rookie
Pine Script Rookie
Posts: 3
Joined: February 10th, 2023
Contact: TradingView Profile

I'm not sure how to achieve this and I'm a newbie

Hi everyone,

I'm currently working on this code to make the bars turn grey at a specific time (from 17:00 to 18:00).

This is the code, and it's not working for me.

Code: Select all

study("Grey Bars")

time = time("1700", "Europe/London")
is_grey = (time >= 1700 and time <= 1800)

barcolor(color = is_grey ? #808080 : an)
Can you please help me with the proper correction/code?

Thank you in advance :zen:

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: I'm not sure how to achieve this and I'm a newbie

Hey,

You can use the following

//@version=4
study("Grey Bars")
is_grey = time(timeframe.period, "1700-1800:23456", "Europe/London") this is true if it is between 1700 and 1800 Monday to Friday
barcolor(is_grey ? #808080 : na)

I hope this helps

Pinescripter
Pine Script Rookie
Pine Script Rookie
Posts: 3
Joined: February 10th, 2023
Contact: TradingView Profile

Re: I'm not sure how to achieve this and I'm a newbie

That was very helpful! Thank you so much!

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: I'm not sure how to achieve this and I'm a newbie

Glad to hear it has helped

Return to “Pine Script Q&A”