0

I'm a newb with Pineview and I'm trying to piece together some examples of how to draw a box around the 8am UTC+2 1H candle every day.

I can't seem to figure out how to calculate the coordinates of the box itself. Does anyone have any examples that I could retrofit?

I'm using the https://www.tradingcode.net/tradingview/session-high-low-box/#summary as a template

`

//@version=5
indicator("Daily 00", overlay=true)
var op1 = 0.0
var op2 = 0.0
var startindex=0
c_green = color.rgb(33, 150, 243, 80)
op1 := (hour== 5 and minute == 0) ? open : op1[1]
op2 := (hour== 12 and minute == 0) ? open : op2[1]
startindex := (hour== 5 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)
Joe R
  • 1

1 Answers1

0

This is most likely caused due to the lack of bar that has the exact time of 5:00 or 12:00.

Since you are looking for a range of bars in a specific session, you can try using a session instead and check if the bar is within that session:

//@version=5
indicator("Daily 00", overlay=true)

sessionInfo = input.session("0500-1200", "Session")
inSession = not na(time(timeframe.period, sessionInfo))

startSession = inSession and not inSession[1]
endSession = not inSession and inSession[1]

var op1 = 0.0
var startindex = 0

if startSession
    startindex := bar_index
    op1 := open

var op2 = 0.0
var endindex = 0

if endSession
    endindex := bar_index
    op2 := open

c_green = color.rgb(33, 150, 243, 80)

if endSession
    box.new(startindex, op1, bar_index[1], op2,bgcolor=c_green, border_width=0,border_style=line.style_dashed)
mr_statler
  • 1,913
  • 2
  • 3
  • 14