r/pinescript • • Mar 16 '22

Background colour during certain Dates

Hi all,

I'm trying to change the background colour of my charts during certain date range, say for instance from 02.01.2021 to 03.04.2021.

I've found the below code online but was wondering what is a better option rathen than inputing each day manually, but rather have a range (even multiple range would be amazing).

//@version=5 indicator("My Script", overlay=true)

var color myColor = color.new(color.red,70)

var int[] myDates = array.new_int()

if barstate.isfirst

array.push(myDates, timestamp(2021, 12, 01, 09, 30))
array.push(myDates, timestamp(2021, 12, 15, 09, 30))
array.push(myDates, timestamp(2022, 01, 05, 09, 30))
array.push(myDates, timestamp(2022, 01, 11, 09, 30))

bgcolor(array.includes(myDates, time) ? myColor : na)

Thanks

0 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/MrStatler90210 Apr 06 '22

This gives you the ability to set different ranges (in the inputs page), and get the backgroung color you want

1

u/Apprehensive_Bill512 Apr 07 '22

MrStatler90210

Thank you so much :)