Reputation: 13
I'm trying to display a box based on specific time in a day. The box should be displayed let's say between 9-12am (options to choose how many previous days to be displayed), top and bottom values for the box to be taken from the open of hour 2 and 4. I've made a screenshot to illustrate better what I want to achieve. Basically what's marked in yellow square. I've used the code bellow just for top and bottom values, but I can only get the values from the current day...
//@version=5
indicator("SSS", overlay=true)
var op1 = 0.0
var op2 = 0.0
op1 := (hour== 2 and minute == 0) ? open : op1
op2 := (hour== 4 and minute == 0) ? open : op2
c_green = color.rgb(33, 150, 243, 80)
b1 = box(na)
if barstate.islast
b1 := box.new(bar_index[20], op1, bar_index, op2,
bgcolor=c_green, border_width=0,border_style=line.style_dashed)
box.delete(b1[1])
Any help please ?
Upvotes: 1
Views: 2337
Reputation: 1368
You can save the bar index at hour 9 and then at hour 12 you can draw the box.
//@version=5
indicator("SSS", overlay=true)
var op1 = 0.0
var op2 = 0.0
var startindex=0
c_green = color.rgb(33, 150, 243, 80)
op1 := (hour== 2 and minute == 0) ? open : op1[1]
op2 := (hour== 4 and minute == 0) ? open : op2[1]
startindex := (hour== 9 and minute == 0) ? bar_index : startindex[1]
if (hour== 12 and minute == 0)
box.new(startindex, op1, bar_index, op2,bgcolor=c_green, border_width=0,border_style=line.style_dashed)
Upvotes: 2