Session Open Price
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © zubzero

//@version=5

indicator("Session Open Price", "Session Open Price", true, max_lines_count=500)

// New York Open

iMTimey    = input.session ('0830-0831:1234567', "Session", group="New York Open")
iMStyley   = input.string  ("Dashed", "Line Style", options=["Solid", "Dotted", "Dashed"], group="New York Open")
iMColory   = input.color   (color.new(#ff9800,0), "Color", group="New York Open")
iMLabely   = input.bool    (true, "Show Label", group="New York Open")


tMidnighty = time          ("1", iMTimey)

_MStyley   = iMStyley ==    "Solid" ? line.style_solid : iMStyley == "Dotted" ? line.style_dotted : line.style_dashed


var line lney = na
var openMidnighty  = 0.0

if tMidnighty
    if not tMidnighty[1]
        openMidnighty  := open
    else
        openMidnighty := math.max(open, openMidnighty)
if openMidnighty != openMidnighty[1]
    if barstate.isconfirmed
        line.set_x2(lney, tMidnighty)
        lney := line.new(tMidnighty, openMidnighty, last_bar_time + 14400000/2, openMidnighty, xloc.bar_time, extend.none, iMColory, _MStyley, 1)
        
// London Open

iMTimel    = input.session ('0300-0301:1234567', "Session", group="London Open")
iMStylel   = input.string  ("Dashed", "Line Style", options=["Solid", "Dotted", "Dashed"], group="London Open")
iMColorl   = input.color   (color.new(#2196f3,0), "Color", group="London Open")
iMLabell   = input.bool    (true, "Show Label", group="London Open")


tMidnightl = time          ("1", iMTimel)

_MStylel   = iMStylel ==    "Solid" ? line.style_solid : iMStylel == "Dotted" ? line.style_dotted : line.style_dashed


var line lnel = na
var openMidnightl  = 0.0

if tMidnightl
    if not tMidnightl[1]
        openMidnightl  := open
    else
        openMidnightl := math.max(open, openMidnightl)
if openMidnightl != openMidnightl[1]
    if barstate.isconfirmed
        line.set_x2(lnel, tMidnightl)
        lnel := line.new(tMidnightl, openMidnightl, last_bar_time + 14400000/2, openMidnightl, xloc.bar_time, extend.none, iMColorl, _MStylel, 1)
        
// Frankfurt Open

iMTimef    = input.session ('0200-0201:1234567', "Session", group="Frankfurt Open")
iMStylef   = input.string  ("Dashed", "Line Style", options=["Solid", "Dotted", "Dashed"], group="Frankfurt Open")
iMColorf   = input.color   (color.new(#25ff00,0), "Color", group="Frankfurt Open")
iMLabelf   = input.bool    (true, "Show Label", group="Frankfurt Open")


tMidnightf = time          ("1", iMTimef)

_MStylef   = iMStylef ==    "Solid" ? line.style_solid : iMStylef == "Dotted" ? line.style_dotted : line.style_dashed


var line lnef = na
var openMidnightf  = 0.0

if tMidnightf
    if not tMidnightf[1]
        openMidnightf  := open
    else
        openMidnightf := math.max(open, openMidnightf)
if openMidnightf != openMidnightf[1]
    if barstate.isconfirmed
        line.set_x2(lnef, tMidnightf)
        lnef := line.new(tMidnightf, openMidnightf, last_bar_time + 14400000/2, openMidnightf, xloc.bar_time, extend.none, iMColorf, _MStylef, 1)

// New York Midnight Open

iMTime    = input.session ('0000-0001:1234567', "Session", group="New York Midnight Open")
iMStyle   = input.string  ("Dashed", "Line Style", options=["Solid", "Dotted", "Dashed"], group="New York Midnight Open")
iMColor   = input.color   (color.new(#e91e63,0), "Color", group="New York Midnight Open")
iMLabel   = input.bool    (true, "Show Label", group="New York Midnight Open")


tMidnight = time          ("1", iMTime)

_MStyle   = iMStyle ==    "Solid" ? line.style_solid : iMStyle == "Dotted" ? line.style_dotted : line.style_dashed


var line lne = na
var openMidnight  = 0.0

if tMidnight
    if not tMidnight[1]
        openMidnight  := open
    else
        openMidnight := math.max(open, openMidnight)
if openMidnight != openMidnight[1]
    if barstate.isconfirmed
        line.set_x2(lne, tMidnight)
        lne := line.new(tMidnight, openMidnight, last_bar_time + 14400000/2, openMidnight, xloc.bar_time, extend.none, iMColor, _MStyle, 1)
        