// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gambcl
//@version=6
indicator("Intraday Levels", overlay = true)
////////////////////////////////////////////////////////////////////////////////////////////////////
// Version History
////////////////////////////////////////////////////////////////////////////////////////////////////
// v1.1.0
// - Split out Opening Range and Initial Balance into separate indicators
// v1.0.0
// - Initial release
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////////////////////////////////////////////////////////
var PREV_DAILY_OHLC_GROUP = "PREVIOUS DAILY OHLC"
var PREV_WEEKLY_OHLC_GROUP = "PREVIOUS WEEKLY OHLC"
var ASIA_SESSION_GROUP = "ASIA SESSION"
var LONDON_SESSION_GROUP = "LONDON SESSION"
var NYK_SESSION_GROUP = "NEW YORK SESSION"
var DISPLAY_GROUP = "DISPLAY"
var DEVELOPER_GROUP = "DEVELOPER"
var int SESSION_BORDER_TRANSPARENCY = 50
var int SESSION_BACKGROUND_TRANSPARENCY = 90
////////////////////////////////////////////////////////////////////////////////////////////////////
// Inputs
////////////////////////////////////////////////////////////////////////////////////////////////////
i_show_pwo = input.bool(false, "Previous Weekly Open", inline = "PWO", group = PREV_WEEKLY_OHLC_GROUP, display = display.none)
i_pwo_color = input.color(color.white, "", inline = "PWO", group = PREV_WEEKLY_OHLC_GROUP, active = i_show_pwo, display = display.none)
i_show_pwh = input.bool(true, "Previous Weekly High", inline = "PWH", group = PREV_WEEKLY_OHLC_GROUP, display = display.none)
i_pwh_color = input.color(color.white, "", inline = "PWH", group = PREV_WEEKLY_OHLC_GROUP, active = i_show_pwh, display = display.none)
i_show_pwl = input.bool(true, "Previous Weekly Low", inline = "PWL", group = PREV_WEEKLY_OHLC_GROUP, display = display.none)
i_pwl_color = input.color(color.white, "", inline = "PWL", group = PREV_WEEKLY_OHLC_GROUP, active = i_show_pwl, display = display.none)
i_show_pwc = input.bool(false, "Previous Weekly Close", inline = "PWC", group = PREV_WEEKLY_OHLC_GROUP, display = display.none)
i_pwc_color = input.color(color.white, "", inline = "PWC", group = PREV_WEEKLY_OHLC_GROUP, active = i_show_pwc, display = display.none)
i_show_pdo = input.bool(false, "Previous Daily Open", inline = "PDO", group = PREV_DAILY_OHLC_GROUP, display = display.none)
i_pdo_color = input.color(color.white, "", inline = "PDO", group = PREV_DAILY_OHLC_GROUP, active = i_show_pdo, display = display.none)
i_show_pdh = input.bool(true, "Previous Daily High", inline = "PDH", group = PREV_DAILY_OHLC_GROUP, display = display.none)
i_pdh_color = input.color(color.white, "", inline = "PDH", group = PREV_DAILY_OHLC_GROUP, active = i_show_pdh, display = display.none)
i_show_pdl = input.bool(true, "Previous Daily Low", inline = "PDL", group = PREV_DAILY_OHLC_GROUP, display = display.none)
i_pdl_color = input.color(color.white, "", inline = "PDL", group = PREV_DAILY_OHLC_GROUP, active = i_show_pdl, display = display.none)
i_show_pdc = input.bool(false, "Previous Daily Close", inline = "PDC", group = PREV_DAILY_OHLC_GROUP, display = display.none)
i_pdc_color = input.color(color.white, "", inline = "PDC", group = PREV_DAILY_OHLC_GROUP, active = i_show_pdc, display = display.none)
i_asia_session = input.session("1800-0200", "Asia Session", inline = "Asia Session", group = ASIA_SESSION_GROUP, display = display.none)
i_asia_tz = input.string("America/New_York", "", inline = "Asia Session", group = ASIA_SESSION_GROUP, display = display.none)
i_show_asia_box = input.bool(true, "Show Asia Session", inline = "Asia Box", group = ASIA_SESSION_GROUP, display = display.none)
i_asia_color = input.color(color.orange, "", inline = "Asia Box", group = ASIA_SESSION_GROUP, active = i_show_asia_box, display = display.none)
i_show_asia_o = input.bool(false, "Asia Open", inline = "AO", group = ASIA_SESSION_GROUP, display = display.none)
i_asia_o_color = input.color(color.white, "", inline = "AO", group = ASIA_SESSION_GROUP, active = i_show_asia_o, display = display.none)
i_show_asia_h = input.bool(true, "Asia High", inline = "AH", group = ASIA_SESSION_GROUP, display = display.none)
i_asia_h_color = input.color(color.white, "", inline = "AH", group = ASIA_SESSION_GROUP, active = i_show_asia_h, display = display.none)
i_show_asia_l = input.bool(true, "Asia Low", inline = "AL", group = ASIA_SESSION_GROUP, display = display.none)
i_asia_l_color = input.color(color.white, "", inline = "AL", group = ASIA_SESSION_GROUP, active = i_show_asia_l, display = display.none)
i_show_asia_c = input.bool(false, "Asia Close", inline = "AC", group = ASIA_SESSION_GROUP, display = display.none)
i_asia_c_color = input.color(color.white, "", inline = "AC", group = ASIA_SESSION_GROUP, active = i_show_asia_c, display = display.none)
i_london_session = input.session("0200-0930", "London Session", inline = "London Session", group = LONDON_SESSION_GROUP, display = display.none)
i_london_tz = input.string("America/New_York", "", inline = "London Session", group = LONDON_SESSION_GROUP, display = display.none)
i_show_london_box = input.bool(true, "Show London Session", inline = "London Box", group = LONDON_SESSION_GROUP, display = display.none)
i_london_color = input.color(color.teal, "", inline = "London Box", group = LONDON_SESSION_GROUP, active = i_show_london_box, display = display.none)
i_show_london_o = input.bool(false, "London Open", inline = "LO", group = LONDON_SESSION_GROUP, display = display.none)
i_london_o_color = input.color(color.white, "", inline = "LO", group = LONDON_SESSION_GROUP, active = i_show_london_o, display = display.none)
i_show_london_h = input.bool(true, "London High", inline = "LH", group = LONDON_SESSION_GROUP, display = display.none)
i_london_h_color = input.color(color.white, "", inline = "LH", group = LONDON_SESSION_GROUP, active = i_show_london_h, display = display.none)
i_show_london_l = input.bool(true, "London Low", inline = "LL", group = LONDON_SESSION_GROUP, display = display.none)
i_london_l_color = input.color(color.white, "", inline = "LL", group = LONDON_SESSION_GROUP, active = i_show_london_l, display = display.none)
i_show_london_c = input.bool(false, "London Close", inline = "LC", group = LONDON_SESSION_GROUP, display = display.none)
i_london_c_color = input.color(color.white, "", inline = "LC", group = LONDON_SESSION_GROUP, active = i_show_london_c, display = display.none)
i_nyk_session = input.session("0930-1700", "New York Session", inline = "NYK Session", group = NYK_SESSION_GROUP, display = display.none)
i_nyk_tz = input.string("America/New_York", "", inline = "NYK Session", group = NYK_SESSION_GROUP, display = display.none)
i_show_labels = input.bool(true, "Show Labels", group = DISPLAY_GROUP, display = display.none)
enum VersionEnum
version = "v1.1.0"
VersionEnum i_version = input.enum(VersionEnum.version, "Version", display = display.none, group = DEVELOPER_GROUP)
////////////////////////////////////////////////////////////////////////////////////////////////////
// Functions
////////////////////////////////////////////////////////////////////////////////////////////////////
request_security_no_repaint(timeframe, expression) =>
request.security(symbol = syminfo.tickerid, timeframe = timeframe, expression = expression[barstate.isrealtime ? 1 : 0], gaps = barmerge.gaps_off)[barstate.isrealtime ? 0 : 1] // PineCoders best practice.
////////////////////////////////////////////////////////////////////////////////////////////////////
// Daily Reset
////////////////////////////////////////////////////////////////////////////////////////////////////
var float asia_o = na
var float asia_h = na
var float asia_l = na
var float asia_c = na
var bool asia_closed = false
var label lbl_asia_o = na
var label lbl_asia_h = na
var label lbl_asia_l = na
var label lbl_asia_c = na
var float london_o = na
var float london_h = na
var float london_l = na
var float london_c = na
var bool london_closed = false
var label lbl_london_o = na
var label lbl_london_h = na
var label lbl_london_l = na
var label lbl_london_c = na
if barstate.isnew and not na(time("", i_nyk_session, i_nyk_tz, 1)) and na(time("", i_nyk_session, i_nyk_tz, 0))
asia_o := na
asia_h := na
asia_l := na
asia_c := na
asia_closed := false
london_o := na
london_h := na
london_l := na
london_c := na
london_closed := false
if i_show_labels
if not na(lbl_asia_o)
lbl_asia_o.delete()
lbl_asia_o := na
if not na(lbl_asia_h)
lbl_asia_h.delete()
lbl_asia_h := na
if not na(lbl_asia_l)
lbl_asia_l.delete()
lbl_asia_l := na
if not na(lbl_asia_c)
lbl_asia_c.delete()
lbl_asia_c := na
if not na(lbl_london_o)
lbl_london_o.delete()
lbl_london_o := na
if not na(lbl_london_h)
lbl_london_h.delete()
lbl_london_h := na
if not na(lbl_london_l)
lbl_london_l.delete()
lbl_london_l := na
if not na(lbl_london_c)
lbl_london_c.delete()
lbl_london_c := na
////////////////////////////////////////////////////////////////////////////////////////////////////
// Previous Daily Open/High/Low/Close
////////////////////////////////////////////////////////////////////////////////////////////////////
var bool show_daily_levels = timeframe.in_seconds() <= timeframe.in_seconds("D")
var float pdo = na
var float pdh = na
var float pdl = na
var float pdc = na
daily_bar_index = request_security_no_repaint("D", bar_index)
pdo_request = request_security_no_repaint("D", open)
pdh_request = request_security_no_repaint("D", high)
pdl_request = request_security_no_repaint("D", low)
pdc_request = request_security_no_repaint("D", close)
if daily_bar_index != daily_bar_index[1]
pdo := pdo_request
pdh := pdh_request
pdl := pdl_request
pdc := pdc_request
plot(show_daily_levels and i_show_pdo and (daily_bar_index == daily_bar_index[1]) ? pdo : na, "PDO", i_pdo_color, 2, plot.style_steplinebr, offset = -1)
plot(show_daily_levels and i_show_pdh and (daily_bar_index == daily_bar_index[1]) ? pdh : na, "PDH", i_pdh_color, 2, plot.style_steplinebr, offset = -1)
plot(show_daily_levels and i_show_pdl and (daily_bar_index == daily_bar_index[1]) ? pdl : na, "PDL", i_pdl_color, 2, plot.style_steplinebr, offset = -1)
plot(show_daily_levels and i_show_pdc and (daily_bar_index == daily_bar_index[1]) ? pdc : na, "PDC", i_pdc_color, 2, plot.style_steplinebr, offset = -1)
var label lbl_pdo = (show_daily_levels and i_show_labels and i_show_pdo) ? label.new(bar_index, pdo, "PDO", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_pdo_color, size.normal, text.align_left, "Previous Daily Open") : na
var label lbl_pdh = (show_daily_levels and i_show_labels and i_show_pdh) ? label.new(bar_index, pdh, "PDH", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_pdh_color, size.normal, text.align_left, "Previous Daily High") : na
var label lbl_pdl = (show_daily_levels and i_show_labels and i_show_pdl) ? label.new(bar_index, pdl, "PDL", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_pdl_color, size.normal, text.align_left, "Previous Daily Low") : na
var label lbl_pdc = (show_daily_levels and i_show_labels and i_show_pdc) ? label.new(bar_index, pdc, "PDC", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_pdc_color, size.normal, text.align_left, "Previous Daily Close") : na
if show_daily_levels and i_show_labels
if not na(lbl_pdo)
lbl_pdo.set_xy(bar_index, pdo)
if not na(lbl_pdh)
lbl_pdh.set_xy(bar_index, pdh)
if not na(lbl_pdl)
lbl_pdl.set_xy(bar_index, pdl)
if not na(lbl_pdc)
lbl_pdc.set_xy(bar_index, pdc)
////////////////////////////////////////////////////////////////////////////////////////////////////
// Previous Weekly Open/High/Low/Close
////////////////////////////////////////////////////////////////////////////////////////////////////
var bool show_weekly_levels = timeframe.in_seconds() <= timeframe.in_seconds("W")
var float pwo = na
var float pwh = na
var float pwl = na
var float pwc = na
weekly_bar_index = request_security_no_repaint("W", bar_index)
pwo_request = request_security_no_repaint("W", open)
pwh_request = request_security_no_repaint("W", high)
pwl_request = request_security_no_repaint("W", low)
pwc_request = request_security_no_repaint("W", close)
if weekly_bar_index != weekly_bar_index[1]
pwo := pwo_request
pwh := pwh_request
pwl := pwl_request
pwc := pwc_request
plot(show_weekly_levels and i_show_pwo and (weekly_bar_index == weekly_bar_index[1]) ? pwo : na, "PWO", i_pwo_color, 2, plot.style_steplinebr, offset = -1)
plot(show_weekly_levels and i_show_pwh and (weekly_bar_index == weekly_bar_index[1]) ? pwh : na, "PWH", i_pwh_color, 2, plot.style_steplinebr, offset = -1)
plot(show_weekly_levels and i_show_pwl and (weekly_bar_index == weekly_bar_index[1]) ? pwl : na, "PWL", i_pwl_color, 2, plot.style_steplinebr, offset = -1)
plot(show_weekly_levels and i_show_pwc and (weekly_bar_index == weekly_bar_index[1]) ? pwc : na, "PWC", i_pwc_color, 2, plot.style_steplinebr, offset = -1)
var label lbl_pwo = (show_weekly_levels and i_show_labels and i_show_pwo) ? label.new(bar_index, pwo, "PWO", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_pwo_color, size.normal, text.align_left, "Previous Weekly Open") : na
var label lbl_pwh = (show_weekly_levels and i_show_labels and i_show_pwh) ? label.new(bar_index, pwh, "PWH", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_pwh_color, size.normal, text.align_left, "Previous Weekly High") : na
var label lbl_pwl = (show_weekly_levels and i_show_labels and i_show_pwl) ? label.new(bar_index, pwl, "PWL", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_pwl_color, size.normal, text.align_left, "Previous Weekly Low") : na
var label lbl_pwc = (show_weekly_levels and i_show_labels and i_show_pwc) ? label.new(bar_index, pwc, "PWC", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_pwc_color, size.normal, text.align_left, "Previous Weekly Close") : na
if show_weekly_levels and i_show_labels
if not na(lbl_pwo)
lbl_pwo.set_xy(bar_index, pwo)
if not na(lbl_pwh)
lbl_pwh.set_xy(bar_index, pwh)
if not na(lbl_pwl)
lbl_pwl.set_xy(bar_index, pwl)
if not na(lbl_pwc)
lbl_pwc.set_xy(bar_index, pwc)
////////////////////////////////////////////////////////////////////////////////////////////////////
// Asia Session
////////////////////////////////////////////////////////////////////////////////////////////////////
var bool show_asia_session = (timeframe.in_seconds() <= timeframe.in_seconds("30")) and ((timeframe.in_seconds("30") % timeframe.in_seconds()) == 0)
var box asia_box = na
if show_asia_session
// Check for entering Asia session
if na(time("", i_asia_session, i_asia_tz, 1)) and not na(time("", i_asia_session, i_asia_tz))
// Just entered Asia session
asia_closed := false
asia_o := open
asia_h := high
asia_l := low
asia_c := close
if i_show_asia_box
asia_box := box.new(bar_index, asia_h, bar_index, asia_l, color.new(i_asia_color, SESSION_BORDER_TRANSPARENCY), 1, line.style_solid, extend.none, xloc.bar_index, color.new(i_asia_color, SESSION_BACKGROUND_TRANSPARENCY), "Asia", size.normal, color.new(i_asia_color, SESSION_BORDER_TRANSPARENCY), text.align_center, text.align_top)
else if not na(time("", i_asia_session, i_asia_tz))
// In Asia session
asia_h := math.max(high, asia_h)
asia_l := math.min(low, asia_l)
asia_c := close
if i_show_asia_box
asia_box.set_right(bar_index)
asia_box.set_top(asia_h)
asia_box.set_bottom(asia_l)
else if not na(time("", i_asia_session, i_asia_tz, 1)) and na(time("", i_asia_session, i_asia_tz))
// Just left Asia session
asia_closed := true
lbl_asia_o := (show_asia_session and i_show_labels and i_show_asia_o) ? label.new(bar_index, asia_o, "Asia Open", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_asia_o_color, size.normal, text.align_left, "Asia Open") : na
lbl_asia_h := (show_asia_session and i_show_labels and i_show_asia_h) ? label.new(bar_index, asia_h, "Asia High", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_asia_h_color, size.normal, text.align_left, "Asia High") : na
lbl_asia_l := (show_asia_session and i_show_labels and i_show_asia_l) ? label.new(bar_index, asia_l, "Asia Low", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_asia_l_color, size.normal, text.align_left, "Asia Low") : na
lbl_asia_c := (show_asia_session and i_show_labels and i_show_asia_c) ? label.new(bar_index, asia_c, "Asia Close", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_asia_c_color, size.normal, text.align_left, "Asia Close") : na
plot(show_asia_session and asia_closed and i_show_asia_o ? asia_o : na, "Asia Open", i_asia_o_color, 2, plot.style_steplinebr, offset = 0)
plot(show_asia_session and asia_closed and i_show_asia_h ? asia_h : na, "Asia High", i_asia_h_color, 2, plot.style_steplinebr, offset = 0)
plot(show_asia_session and asia_closed and i_show_asia_l ? asia_l : na, "Asia Low", i_asia_l_color, 2, plot.style_steplinebr, offset = 0)
plot(show_asia_session and asia_closed and i_show_asia_c ? asia_c : na, "Asia Close", i_asia_c_color, 2, plot.style_steplinebr, offset = 0)
if show_asia_session and i_show_labels
if not na(lbl_asia_o)
lbl_asia_o.set_xy(bar_index, asia_o)
if not na(lbl_asia_h)
lbl_asia_h.set_xy(bar_index, asia_h)
if not na(lbl_asia_l)
lbl_asia_l.set_xy(bar_index, asia_l)
if not na(lbl_asia_c)
lbl_asia_c.set_xy(bar_index, asia_c)
////////////////////////////////////////////////////////////////////////////////////////////////////
// London Session
////////////////////////////////////////////////////////////////////////////////////////////////////
var bool show_london_session = (timeframe.in_seconds() <= timeframe.in_seconds("30")) and ((timeframe.in_seconds("30") % timeframe.in_seconds()) == 0)
var box london_box = na
if show_london_session
// Check for entering London session
if na(time("", i_london_session, i_london_tz, 1)) and not na(time("", i_london_session, i_london_tz))
// Just entered London session
london_closed := false
london_o := open
london_h := high
london_l := low
london_c := close
if i_show_london_box
london_box := box.new(bar_index, london_h, bar_index, london_l, color.new(i_london_color, SESSION_BORDER_TRANSPARENCY), 1, line.style_solid, extend.none, xloc.bar_index, color.new(i_london_color, SESSION_BACKGROUND_TRANSPARENCY), "London", size.normal, color.new(i_london_color, SESSION_BORDER_TRANSPARENCY), text.align_center, text.align_top)
else if not na(time("", i_london_session, i_london_tz))
// In London session
london_h := math.max(high, london_h)
london_l := math.min(low, london_l)
london_c := close
if i_show_london_box
london_box.set_right(bar_index)
london_box.set_top(london_h)
london_box.set_bottom(london_l)
else if not na(time("", i_london_session, i_london_tz, 1)) and na(time("", i_london_session, i_london_tz))
// Just left London session
london_closed := true
lbl_london_o := (show_london_session and i_show_labels and i_show_london_o) ? label.new(bar_index, london_o, "London Open", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_london_o_color, size.normal, text.align_left, "London Open") : na
lbl_london_h := (show_london_session and i_show_labels and i_show_london_h) ? label.new(bar_index, london_h, "London High", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_london_h_color, size.normal, text.align_left, "London High") : na
lbl_london_l := (show_london_session and i_show_labels and i_show_london_l) ? label.new(bar_index, london_l, "London Low", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_london_l_color, size.normal, text.align_left, "London Low") : na
lbl_london_c := (show_london_session and i_show_labels and i_show_london_c) ? label.new(bar_index, london_c, "London Close", xloc.bar_index, yloc.price, color.new(color.black, 100), label.style_label_left, i_london_c_color, size.normal, text.align_left, "London Close") : na
plot(show_london_session and london_closed and i_show_london_o ? london_o : na, "London Open", i_london_o_color, 2, plot.style_steplinebr, offset = 0)
plot(show_london_session and london_closed and i_show_london_h ? london_h : na, "London High", i_london_h_color, 2, plot.style_steplinebr, offset = 0)
plot(show_london_session and london_closed and i_show_london_l ? london_l : na, "London Low", i_london_l_color, 2, plot.style_steplinebr, offset = 0)
plot(show_london_session and london_closed and i_show_london_c ? london_c : na, "London Close", i_london_c_color, 2, plot.style_steplinebr, offset = 0)
if show_london_session and i_show_labels
if not na(lbl_london_o)
lbl_london_o.set_xy(bar_index, london_o)
if not na(lbl_london_h)
lbl_london_h.set_xy(bar_index, london_h)
if not na(lbl_london_l)
lbl_london_l.set_xy(bar_index, london_l)
if not na(lbl_london_c)
lbl_london_c.set_xy(bar_index, london_c)
Show all 346 lines