Pinescript - ((time >= time_start) and (time <= time_end)) not working

Viewed 35

Trying to color the background of the chart when the time is between a time start and a time end. I've plotted the values of the start and end values I'm trying to use and the time is deffinetly between the values, yet it doesn't plot right. See Screen Shot 1 and 2 Code:

n_monday     = (dayofweek(time) == dayofweek.monday)
start_of_mon = n_monday and (ta.barssince(n_monday == false) == 1)

n_sunday     = (dayofweek(time) == dayofweek.sunday)
start_of_sun = n_sunday and (ta.barssince(n_sunday == false) == 1)


f_start_monday  = (ta.barssince (start_of_sun) == offset) ? true : na
f_monday        = ta.valuewhen (f_start_monday, time, 0)

f_start_tuesday = (ta.barssince (start_of_mon) == offset) ? true : na
f_tuesday       = ta.valuewhen (f_start_tuesday, time, 0)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if f_start_monday
    label.new (bar_index, 3000, str.tostring (f_monday / 100000))
if f_start_tuesday
    label.new (bar_index, 3000, str.tostring (f_tuesday / 100000))



hs_monday      = ((time >= f_monday) and (time <= f_tuesday))



bgcolor (hs_monday ? color.blue : na)

I've tried using bar_index instead which doesn't work at all. Rearanging the variables that the last use, rewording them, nothing seems to work, even though time is very clearly between the values given on the labels. (Note I did divide the text on the labels by 100000 for easy reading). Thanks so much for your help in advance!

enter image description here

enter image description here

1 Answers

The problem was with the precision, and the f_tuesday variable. I instead used f_monday + 8400000 (the same value as f_tuesday, just based off f_monday instead). All numbers used were absolutely the same and correct, and I have no idea why this worked instead of the former, pinescript am I right?!

I will accept my own answer as soon as stack overflow lets me, so sorry if you were trying to help because it says there hasn't been a solution!

Related