Linea Bruja
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// I took this code from infernixx, so we can say its like a copy, and I took it too, so it's another copy - Carlos K

//@version=4
study("Linea Bruja", overlay = true)

bool show_daily_open = input(group="Daily Open", title="Show daily open", type=input.bool, defval=true)
bool show_daily_open_label = input(group="Daily Open", title="Show daily open label", type=input.bool, defval=true)
color daily_open_color = input(group="Daily Open", title="Daily Open Color", type=input.color, defval=color.new(color.yellow,5))

//Non repainting security
f_security(_symbol, _res, _src, _repaint) => security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]


// Basic vars (needed in functions)

// Only render intraday
validTimeFrame = timeframe.isintraday == true

// If above the 5 minute, we start drawing yesterday. below, we start today
levelsstart = iff((timeframe.isseconds == true) or (timeframe.isminutes == true and timeframe.multiplier < 5), time('D'), time('D') - (86400 * 1000))
levelsstartbar = barssince(levelsstart)


// Functions
// new_bar: check if we're on a new bar within the session in a given resolution
new_bar(res) => change(time(res)) != 0

// Get Daily price data
dayOpen  = f_security(syminfo.tickerid, "D",open, false)


// Daily open 
daily_open = security(syminfo.tickerid, 'D', open, lookahead=barmerge.lookahead_on)
// Date & time variables
current_year = year(timenow)
current_month = month(timenow)
current_weekofyear = weekofyear(timenow)
current_dayofmonth = dayofmonth(timenow)
current_dayofweek = dayofweek(timenow)

// Opens (re-test previous values, so we take the closing price as that is defining the upcoming open price)

bar_is_today = (year == current_year and weekofyear == current_weekofyear and dayofweek == current_dayofweek)
plot(show_daily_open and bar_is_today and validTimeFrame? daily_open : na, title="Daily open", color=daily_open_color, style=plot.style_linebr, linewidth=2)