this is my first post in here and sorry for any mistake I could do in the post, moreover I'm not that practical with PineScript code yet, I'm in the "trial and error" phase.
as per title I would like to know if there is any chance to be able to color the background of the chart specifing how many days from the end of the month and how many days from the beginning of the month.
I did some research and I ended up in this post.
I managed to modify the Version 2 of the code provided by PineCoders-LucF in that post, the only problem is when it comes to weekends the code does not work anymore.
To be more specific:
//@version=4
study("BgColor", overlay=true)
fromDay = input(-4)
toDay = input(+4)
weekdaysOnly = input(true)
useVline = input(false)
dayIsOk = not weekdaysOnly or (dayofweek != dayofweek.saturday and dayofweek != dayofweek.sunday)
t1 = timestamp("GMT-5", year, month, fromDay, 00, 00)
t2 = timestamp("GMT-5", year, month, toDay, 00, 00)
timeIsOk = (time >= t1) and (time <= t2)
bgcolor( not useVline and timeIsOk and dayIsOk ? color.orange : na, transp = 80)
if useVline and timeIsOk and dayIsOk
line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, #FF8000ff, line.style_solid, 1)
It does somehow the job, but as you can see, it has some problems when the weekend is in between the n days specified from the end or beginning of the month.
My question is if its possible to tell to the code to skip the weekend days, and if it's a weekend day then to plot the background color on the first week day availiable.
The other question is: is ther any code to plot the following code in the future? For example specifing with an input how many months forward I would like to see the background color plotted.
Thanks for your kind attention.
Silo