This code produces a rectangle which covers the height of the chart, though the candles are correct. It should only cover from the low to the high of the previous M15 candle. Why is this happening? I can see the previous high and low are correct values and not na
.
isNineAM = (hour(time, 'UTC') == startHour) and (minute == 15)
if isNineAM and not na(high) and not na(low)
log.info(str.tostring(isNineAM)+' '+str.tostring(high[1])+' '+str.tostring(low[1]))
startIndex = bar_index-1
endIndex = bar_index + 32
b = box.new(left=startIndex, top=high[1], right=endIndex, bottom=low[1], border_color=na, bgcolor=white)
I should note that my chart is UTC+2.
Here is the entire indicator in PineScript v6:
//@version=6
indicator("London Session Highlight", overlay=true)
// === Background during London session (08:00–17:00 UTC+2) ===
startHour = 8
startMin = 0
endHour = 16
endMin = 15
sessionStart = timestamp('UTC', year, month, dayofmonth, startHour, startMin)
sessionEnd = timestamp('UTC', year, month, dayofmonth, endHour, endMin)
isInSession = sessionStart <= time and time <= sessionEnd
bgcolor(isInSession ? color.new(color.blue, 80) : na)
var white = color.new(color.white, 80)
isNineAM = (hour(time, 'UTC') == startHour) and (minute == 15)
if isNineAM and not na(high) and not na(low)
log.info(str.tostring(isNineAM)+' '+str.tostring(high[1])+' '+str.tostring(low[1]))
startIndex = bar_index-1
endIndex = bar_index + 32
b = box.new(left=startIndex, top=high[1], right=endIndex, bottom=low[1], border_color=na, bgcolor=white)
This is what I see when the indicator is added to my chart:
What's really strange, that I only just noticed, is that if I scale down the size of the box suddenly jumps to much smaller, when the previous box comes into view - could this be due to something like variable references?
Here's what I expected, with the expected boxes added in yellow and the actual boxes still in white:
Your code seems to be fine. Whenever your drawings change when you move your chart around, always check the scale that is selected and make sure it is pinned to right scale.
Click on the three dots next to your indicator's name on your chart and set your scale.