OPEN-SOURCE SCRIPT

Previous Day OHLC with Labels

60
//version=5
indicator("Previous Day OHLC with Labels (Visible Fix)", overlay=true)

// ========== SETTINGS ==========
col_open = input.color(color.new(color.green, 0), "Open Line Color")
col_high = input.color(color.new(color.red, 0), "High Line Color")
col_low = input.color(color.new(color.blue, 0), "Low Line Color")
col_close = input.color(color.new(color.yellow, 0), "Close Line Color")
line_w = input.int(2, "Line Width", minval=1, maxval=5)
show_labels = input.bool(true, "Show Labels")

// ========== PREVIOUS DAY DATA ==========
prev_open = request.security(syminfo.tickerid, "D", open[1], lookahead=barmerge.lookahead_on)
prev_high = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
prev_low = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)
prev_close = request.security(syminfo.tickerid, "D", close[1], lookahead=barmerge.lookahead_on)
prev_dow = request.security(syminfo.tickerid, "D", dayofweek[1], lookahead=barmerge.lookahead_on)

// Get day name
day_name = prev_dow == dayofweek.monday ? "Monday" :
prev_dow == dayofweek.tuesday ? "Tuesday" :
prev_dow == dayofweek.wednesday ? "Wednesday" :
prev_dow == dayofweek.thursday ? "Thursday" :
prev_dow == dayofweek.friday ? "Friday" :
prev_dow == dayofweek.saturday ? "Saturday" : "Sunday"

// ========== DRAW LINES ==========
if barstate.islast
// Extend across full chart view
line.new(bar_index - 500, prev_open, bar_index + 500, prev_open, color=col_open, width=line_w, extend=extend.both)
line.new(bar_index - 500, prev_high, bar_index + 500, prev_high, color=col_high, width=line_w, extend=extend.both)
line.new(bar_index - 500, prev_low, bar_index + 500, prev_low, color=col_low, width=line_w, extend=extend.both)
line.new(bar_index - 500, prev_close, bar_index + 500, prev_close, color=col_close, width=line_w, extend=extend.both)

if show_labels
label.new(bar_index + 2, prev_open, str.format("{0} Open {1,number,0.#####}", day_name, prev_open), style=label.style_label_left, textcolor=color.white, color=col_open)
label.new(bar_index + 2, prev_high, str.format("{0} High {1,number,0.#####}", day_name, prev_high), style=label.style_label_left, textcolor=color.white, color=col_high)
label.new(bar_index + 2, prev_low, str.format("{0} Low {1,number,0.#####}", day_name, prev_low), style=label.style_label_left, textcolor=color.white, color=col_low)
label.new(bar_index + 2, prev_close, str.format("{0} Close {1,number,0.#####}", day_name, prev_close), style=label.style_label_left, textcolor=color.white, color=col_close)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.