Seabass16
Pine Script Rookie
Pine Script Rookie
Posts: 3
Joined: September 29th, 2021

Future lines disappearing

I have an indicator that plots lines ahead of Forex price action for the previous day's OLHC. This works well, but come Friday it strangely disappears. I'm wondering if the time calculation is affected by the forthcoming weekend (market close). However, I've been scratching my head to determine the precise cause. Any help would be greatly appreciated.

//@version=5
indicator(title='PrevOLHC', overlay=true, max_labels_count=50, max_lines_count=50)


// ==================================
// Inputs
// ==================================

showD1HighLow = input(title='Show daily high/low', defval=true)


//================================================================================================
//
// CONSTANTS
// =========
//
//================================================================================================

// Time elapsed between candles on any time-frame
int ONE_CANDLE_IN_MILLISECS = time - time[1]

// Time Zone
TIME_ZONE = 'Europe/London'




//============================================================================================================
//
// FUNCTIONS
//
//============================================================================================================





//============================================================================================================
//
// DATA
//
//============================================================================================================

// Get date/time information
currentMinute = minute(time, TIME_ZONE) // 1 - 60
currentHour = hour(time, TIME_ZONE) // 0 - 23
currentMonth = month(time, TIME_ZONE) // 1 - 12
currentYear = year(time, TIME_ZONE)
currentDayOfMonth = dayofmonth(time, TIME_ZONE) // 1 - 31
currentDayOfWeek = dayofweek(time, TIME_ZONE) // 1 - 7
isNewMonth = ta.change(currentMonth)

distanceFromCurrent = 10 // Number of candles
labelDistance = (ONE_CANDLE_IN_MILLISECS * distanceFromCurrent)
lineDistance = (ONE_CANDLE_IN_MILLISECS * (distanceFromCurrent+3))
closeDistance = (ONE_CANDLE_IN_MILLISECS * (distanceFromCurrent+4))



// Declarations
line d1HighLine = na
line d1LowLine = na
line d1OpenLine = na
line d1CloseLine = na
label d1HighLabel = na
label d1LowLabel = na
label d1OpenLabel = na
label d1CloseLabel = na


//delete all lines
//a_allLines = line.all
//if array.size(a_allLines) > 0
// for i = 0 to array.size(a_allLines) - 1
// line.delete(array.get(a_allLines, i))

//a_allLabels = label.all
//if array.size(a_allLabels) > 0
// for i = 0 to array.size(a_allLabels) - 1
// label.delete(array.get(a_allLabels, i))

//============================================================================================================
//
// PREVIOUS DAY'S HIGH, LOW, OPEN, CLOSE
//
//============================================================================================================
[d1High, d1Low, d1Open, d1Close] = request.security(syminfo.tickerid, 'D', [high[1], low[1], open[1], close[1]]) // , barmerge.lookahead_on)

d1lineDistance = (currentDayOfWeek == 6) and (currentHour > 7) ? (lineDistance * 2) : lineDistance
d1closeDistance = (currentDayOfWeek == 6) and (currentHour > 7) ? (closeDistance * 2) : closeDistance
d1labelDistance = (currentDayOfWeek == 6) and (currentHour > 7) ? (labelDistance * 2) : labelDistance

d1Transp = (showD1HighLow == true) ? 20 : 100
d1Color = #FF0FFB // color.new(#FF0FFB, d1Transp)
d1Label = color.new(color.white, d1Transp)
d1HighLine := line.new(x1=time+d1lineDistance, y1=d1High, x2=time+d1closeDistance, y2=d1High, xloc=xloc.bar_time, color=d1Color, extend=extend.right, style=line.style_dotted, width=4)
d1LowLine := line.new(x1=time+d1lineDistance, y1=d1Low, x2=time+d1closeDistance, y2=d1Low, xloc=xloc.bar_time, color=d1Color, extend=extend.right, style=line.style_dotted, width=4)
d1OpenLine := line.new(x1=time+d1lineDistance, y1=d1Open, x2=time+d1closeDistance, y2=d1Open, xloc=xloc.bar_time, color=d1Color, extend=extend.right, style=line.style_dotted, width=2)
d1CloseLine := line.new(x1=time+d1lineDistance, y1=d1Close, x2=time+d1closeDistance, y2=d1Close, xloc=xloc.bar_time, color=d1Color, extend=extend.right, style=line.style_dotted, width=2)
d1HighLabel := label.new(x=time+d1labelDistance, y=d1High, xloc=xloc.bar_time, style= label.style_none, textalign=text.align_left, text="D1 High", textcolor=d1Label)
d1LowLabel := label.new(x=time+d1labelDistance, y=d1Low, xloc=xloc.bar_time, style= label.style_none, textalign=text.align_left, text="D1 Low", textcolor=d1Label)
d1OpenLabel := label.new(x=time+d1labelDistance, y=d1Open, xloc=xloc.bar_time, style= label.style_none, textalign=text.align_left, text="D1 Open", textcolor=d1Label)
d1CloseLabel := label.new(x=time+d1labelDistance, y=d1Close, xloc=xloc.bar_time, style= label.style_none, textalign=text.align_left, text="D1 Close", textcolor=d1Label)

line.delete(d1HighLine[1])
line.delete(d1LowLine[1])
line.delete(d1OpenLine[1])
line.delete(d1CloseLine[1])
label.delete(d1HighLabel[1])
label.delete(d1LowLabel[1])
label.delete(d1OpenLabel[1])
label.delete(d1CloseLabel[1])

Return to “General Trading Discussions”