Session Levels - Ultimate Range Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ArdOfCrypto

//@version=5
indicator("Session Levels", overlay=true, max_bars_back=1000, max_lines_count=500, max_labels_count=500, max_boxes_count=50)

// Sessions and inputs
i_timezone          = input.string(defval="America/Chicago", title="Timezone Selection", options=["GMT", "America/Los_Angeles", "America/Phoenix", "America/Vancouver", "America/El_Salvador", "America/Bogota", "America/Chicago", "America/New_York", "America/Toronto", "America/Argentina/Buenos_Aires", "America/Sao_Paulo", "Etc/UTC", "Europe/Amsterdam", "Europe/London", "Europe/Berlin", "Europe/Madrid", "Europe/Paris", "Europe/Warsaw", "Europe/Athens", "Europe/Moscow", "Asia/Tehran", "Asia/Dubai", "Asia/Ashkhabad", "Asia/Kolkata", "Asia/Almaty", "Asia/Bangkok", "Asia/Hong_Kong", "Asia/Shanghai", "Asia/Singapore", "Asia/Taipei", "Asia/Seoul", "Asia/Tokyo", "Australia/ACT", "Australia/Adelaide", "Australia/Brisbane", "Australia/Sydney", "Pacific/Auckland", "Pacific/Fakaofo", "Pacific/Chatham", "Pacific/Honolulu"], tooltip="Select the Exchange Timezone, or your own. Whatever works best for you.")
i_GlobexSession     = input.session(title="Globex", defval="1700-0830", group="Session Settings", inline="GS")                                                      // Globex (Overnight) Session, Monday - Friday 17:00 - 0830. Globex opens at 5pm CST and closes when the US session starts 8:30CST.
i_GlobexSessionCol  = input.color(title="Session",tooltip="Globex Session Highlight Color", defval=color.silver, group="Session Settings", inline="GS")             // Globex (Overnight) Session, color setting for background highlights
i_GlobexLevelCol    = input.color(title="Levels",tooltip="Globex Levels Color", defval=color.gray, group="Session Settings", inline="GS")                           // Globex (Overnight) Session, color setting for level lines
i_AsianSession      = input.session(title="Asian", defval="1900-0200", group="Session Settings", inline="AS")                                                       // Asian Session, Monday - Friday
i_AsianSessionCol   = input.color(title="Session",tooltip="Asian Session Highlight Color", defval=color.white, group="Session Settings", inline="AS")               // Asian Session, color setting for background highlights, 1st hr box and High and Low lines
i_AsianLevelCol     = input.color(title="Levels",tooltip="Asian Levels Color", defval=color.gray, group="Session Settings", inline="AS")                            // Asian Session, color setting for level lines
i_LondonSession     = input.session(title="London", defval="0300-1100", group="Session Settings", inline="LS")                                                      // London Session, Monday - Friday
i_LondonSessionCol  = input.color(title="Session",tooltip="London Session Highlight Color", defval=color.green, group="Session Settings", inline="LS")              // London Session, color setting for background highlights, 1st hr box and High and Low lines
i_LondonLevelCol    = input.color(title="Levels",tooltip="London Levels Color", defval=color.gray, group="Session Settings", inline="LS")                           // London Session, color setting for level lines
i_NewYorkSession    = input.session(title="New York", defval="0800-1600", group="Session Settings", inline="NY")                                                    // New York Session 
i_NYSessionCol      = input.color(title="Session",tooltip="New York Session Highlight Color", defval=color.blue, group="Session Settings", inline="NY")             // New York Session, color setting for background highlights, 1st hr box and High and Low lines
i_NYLevelCol        = input.color(title="Levels",tooltip="New York Level Color", defval=color.gray, group="Session Settings", inline="NY")                          // New York Session, color setting for level lines
i_NewYorkORoffset   = input.int(title="New York Open Offset", tooltip="New York Session Opening Range Starts after x minutes", defval=30, minval=0, maxval=59, group="Session Settings")     // New York Opening Range Initial Balance Opening Minute
i_NYSessionEndHour  = input.int(title="NY CashSession End Hour", defval=16, minval=0, maxval=23, group="Session Settings", inline="NYE")                            // New York Session Opening Hour
i_NYSessionEndMin   = input.int(title="Min.", defval=59, minval=0, maxval=59, group="Session Settings", inline="NYE", tooltip="This is where all the lines and drawings end. Must be Less than the start of Globex")  // New York Session Opening Minute
GlobexSession       = time(timeframe.period, i_GlobexSession, i_timezone)            // Calculate time for the Globex/Overnight session. 
AsianSession        = time(timeframe.period, i_AsianSession, i_timezone)             // Calculate time for the Asian Session.
LondonSession       = time(timeframe.period, i_LondonSession, i_timezone)            // Calculate time for the London Session.
NewYorkSession      = time(timeframe.period, i_NewYorkSession, i_timezone)           // Calculate time for the New York Session.
var CashSessionEndTime  = timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
srcHi               = input(high, "Source for Highs", inline="Sources", group="Source")     // Set Source for Highs used in calculations
srcLo               = input(low, "Source for Lows", inline="Sources", group="Source")       // Set Source for Lows used in calculations
showGlobex          = input.bool(defval=true, title="Globex Overnight", tooltip="Show Globex Background Highlight", group="Session Highlight")
showAsian           = input.bool(defval=false, title="Asian", tooltip="Show Asian Background Highlight", group="Session Highlight")
showLondon          = input.bool(defval=false, title="London", tooltip="Show London Background Highlight", group="Session Highlight")
showNewYork         = input.bool(defval=true, title="New York", tooltip="Show NY Background Highlight", group="Session Highlight")
showOpenbar         = input.bool(defval=true, title="NY IB Opening Bar", tooltip="Show bar before the NY Initial Balance Highlight", group="Session Highlight")
showGlobexDrawings  = input.bool(defval=true, title="Show Globex/Overnight Levels", tooltip="Show Globex/Overnight Drawings", group="Drawings")
showGlobexTodayDraw = input.bool(defval=true, title="Show Globex Todays Drawings Only", tooltip="Removes all historic drawings for cleaner charts", group="Drawings")
showAsianDrawings   = input.bool(defval=false, title="Show Asian Levels", tooltip="Show Asian Session Drawings ", group="Drawings")
showAsianTodayDraw  = input.bool(defval=false, title="Show Asian Todays Drawings Only", tooltip="Removes all historic drawings for cleaner charts", group="Drawings")
showAsianOR         = input.bool(defval=false, title="Show Asian Opening Range", tooltip="Show Asian Session Initial Balance Box ", group="Drawings")
showAsianORStdev    = input.bool(defval=false, title="Show Asian OR STDEV Projections", tooltip="Show Asian Standard Deviation Levels and Labels on Opening Range", group="Drawings")
showLondonDrawings  = input.bool(defval=false, title="Show London Levels", tooltip="Show London Session Drawings ", group="Drawings")
showLondonTodayDraw = input.bool(defval=false, title="Show London Todays Drawings Only", tooltip="Removes all historic drawings for cleaner charts", group="Drawings")
showLondonOR        = input.bool(defval=false, title="Show London Opening Range", tooltip="Show London Session Initial Balance Box ", group="Drawings")
showLondonORStdev   = input.bool(defval=false, title="Show London OR STDEV Projections", tooltip="Show London Standard Deviation Levels and Labels on Opening Range", group="Drawings")
showNewYorkDrawings = input.bool(defval=true, title="Show New York Levels", tooltip="Show New York Session Session Drawings ", group="Drawings")
showNewYorkTodayDraw= input.bool(defval=false, title="Show New York Todays Drawings Only", tooltip="Removes all historic drawings for cleaner charts", group="Drawings")
showNewYorkOR       = input.bool(defval=true, title="Show New York Opening Range", tooltip="Show New York Session Initial Balance Box ", group="Drawings")
showNewYorkORStdev  = input.bool(defval=false, title="Show New York OR STDEV Projections", tooltip="Show New York Standard Deviation Levels and Labels on Opening Range", group="Drawings")
enableNewYorkalarms = input.bool(defval=false, title="Enable Alarms for the NY Session", tooltip="Alarms when price crosses: Globex Hi and Low; Hi, Lo, 50% OR Levels and 0.5 and 1.0 STDEV Levels", group="Alarms")
showLabels          = input.bool(defval=true, title="Show labels on Level Lines ", tooltip="Show Session Labels on every line", group="Drawings")
showPDO             = input.bool(defval=false, title="Show Previous Day Open   - ", tooltip="Show Previous Days's Open line", group="HTF Levels", inline="PDO")
i_PDOcol            = input.color(title="Color", tooltip="Previous Day Open Line Color", defval=color.white, group="HTF Levels", inline="PDO")
showPDC             = input.bool(defval=true, title="Show Previous Day Close   - ", tooltip="Show Previous Days's Closing line", group="HTF Levels", inline="PDC")
i_PDCcol            = input.color(title="Color", tooltip="Previous Day Close Line Color", defval=color.orange, group="HTF Levels", inline="PDC")
showPWO             = input.bool(defval=true, title="Show Previous Week Open   - ", tooltip="Show Previous Week's Opening price line", group="HTF Levels", inline="PWO")
i_PWOcol            = input.color(title="Color", tooltip="Previous Week Open Line Color", defval=color.lime, group="HTF Levels", inline="PWO")
showPWC             = input.bool(defval=false, title="Show Previous Week Close - ", tooltip="Show Previous Week's Closing line", group="HTF Levels", inline="PWC")
i_PWCcol            = input.color(title="Color", tooltip="Previous Week Close Line Color", defval=color.purple, group="HTF Levels", inline="PWC")
showHTFLabels       = input.bool(defval=true, title="Show Labels on HTF Levels", tooltip="Show Labels on Previous HTF Levels", group="HTF Levels")
showDebug           = input.bool(defval=false, title="Show Debug Value Plots", tooltip="View values in the data window", group="Debug Settings")            // Toggle display of debugging information via plots
showDebugLabels     = input.bool(defval=false, title="Show Debugging Labels", tooltip="View values in labels above certain candles", group="Debug Settings") // Toggle display of debugging information in labels

// Get HTF Values
PreviousDayClose    = request.security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on) // Get the Previous Day's closing price
PreviousDayOpen     = request.security(syminfo.tickerid, "D", open[1], lookahead = barmerge.lookahead_on)  // Get the Previous Day's opening price
PreviousWeekClose   = request.security(syminfo.tickerid, "W", close[1], lookahead = barmerge.lookahead_on) // Get the Previous Week's closing price
PreviousWeekOpen    = request.security(syminfo.tickerid, "W", open[1], lookahead = barmerge.lookahead_on)  // Get the Previous Week's opening price


// Set variables for the sessions
// Globex Overnight session
var float Globex_hi = na        // High for the Globex Session
var float Globex_75 = na        // 75% level for the Globex Session
var float Globex_50 = na        // 50% level for the Globex Session
var float Globex_25 = na        // 25% level for the Globex Session
var float Globex_lo = na        // Low for the Globex Session
var Globex_line_hi  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexLevelCol)      // Globex High line
var Globex_line_75  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexLevelCol)      // Globex 75% line
var Globex_line_50  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexLevelCol)      // Globex 50% line
var Globex_line_25  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexLevelCol)      // Globex 25% line
var Globex_line_lo  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexLevelCol)      // Globex Low line
var GlobexHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var Globex75Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var Globex50Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var Globex25Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var GlobexLowLabel  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var GlobexSessionStart = time    // To register the timestap when the Globex Overnight Session begins
// Asian Session
var float Asian_hi = na        // High for the Asian Session
var float Asian_75 = na        // 75% level for the Asian Session
var float Asian_50 = na        // 50% level for the Asian Session
var float Asian_25 = na        // 25% level for the Asian Session
var float Asian_lo = na        // Low for the Asian Session
var Asian_line_hi  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol)     // Asian High line
var Asian_line_75  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol)     // Asian 75% line
var Asian_line_50  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol)     // Asian 50% line
var Asian_line_25  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol)     // Asian 25% line
var Asian_line_lo  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol)     // Asian Low line
var AsianHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var Asian75Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var Asian50Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var Asian25Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianLowLabel  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianSessionStart = time    // To register the timestap when the Asian Session begins
var AsianORStart   = time
var AsianOREnd     = time + 3600000 // Add one hour in milliseconds
// Asian Opening Range (1st Hour)
var float AsianHr1hi     = na       // High for the 1st Hour Session
var float AsianHr1mid    = na       // 50% of the 1st Hour Session
var float AsianHr1lo     = na       // Low for the 1st Hour Session
var AsianOR_line_hi     = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianSessionCol) // Opening Range High
var AsianOR_line_mid    = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianSessionCol) // Opening Range Middle
var AsianOR_line_lo     = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianSessionCol) // Opening Range Low
var AsianOR_line_hi05   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.teal )        // Opening Range High 0.5 STDEV of OR
var AsianOR_line_hi10   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 1.0 STDEV of OR
var AsianOR_line_hi15   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.5 STDEV of OR
var AsianOR_line_hi175  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.75 STDEV of OR
var AsianOR_line_hi20   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 2.0 STDEV of OR
var AsianOR_line_hi225  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.25 STDEV of OR
var AsianOR_line_hi25   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.5 STDEV of OR
var AsianOR_line_hi30   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 3.0 STDEV of OR
var AsianOR_line_lo05   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.maroon )      // Opening Range Low 0.5 STDEV of OR
var AsianOR_line_lo10   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 1.0 STDEV of OR
var AsianOR_line_lo15   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.5 STDEV of OR
var AsianOR_line_lo175  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.75 STDEV of OR
var AsianOR_line_lo20   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 2.0 STDEV of OR
var AsianOR_line_lo225  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.25 STDEV of OR
var AsianOR_line_lo25   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.5 STDEV of OR
var AsianOR_line_lo30   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 3.0 STDEV of OR
var AsianORBox          = box.new(left=AsianORStart, top=na, right=AsianOREnd, bottom=na, xloc=xloc.bar_time, border_width=2, border_color=color.new(i_AsianSessionCol, 100), bgcolor=color.new(i_AsianSessionCol, 70))
var AsianORLabel        = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelHigh    = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelHigh05  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelHigh10  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelHigh20  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelHigh30  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelLow     = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelLow05   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelLow10   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelLow20   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelLow30   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var AsianORLabelMid     = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
// ***
// London Session
var float London_hi = na        // High for the London Session
var float London_75 = na        // 75% level for the London Session
var float London_50 = na        // 50% level for the London Session
var float London_25 = na        // 25% level for the London Session
var float London_lo = na        // Low for the London Session
var London_line_hi  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol)     // London High line
var London_line_75  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol)     // London 75% line
var London_line_50  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol)     // London 50% line
var London_line_25  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol)     // London 25% line
var London_line_lo  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol)     // London Low line
var LondonHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var London75Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var London50Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var London25Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonLowLabel  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonSessionStart = time    // To register the timestap when the London Session begins
var LondonORStart   = time  
var LondonOREnd     = time + 3600000 // Add one hour in milliseconds
// London Opening Range (1st Hour)
var float LondonHr1hi     = na       // High for the 1st Hour Session
var float LondonHr1mid    = na       // 50% of the 1st Hour Session
var float LondonHr1lo     = na       // Low for the 1st Hour Session
var LondonOR_line_hi     = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonSessionCol) // Opening Range High
var LondonOR_line_mid    = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonSessionCol) // Opening Range Middle
var LondonOR_line_lo     = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonSessionCol) // Opening Range Low
var LondonOR_line_hi05   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.teal )        // Opening Range High 0.5 STDEV of OR
var LondonOR_line_hi10   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 1.0 STDEV of OR
var LondonOR_line_hi15   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.5 STDEV of OR
var LondonOR_line_hi175  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.75 STDEV of OR
var LondonOR_line_hi20   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 2.0 STDEV of OR
var LondonOR_line_hi225  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.25 STDEV of OR
var LondonOR_line_hi25   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.5 STDEV of OR
var LondonOR_line_hi30   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 3.0 STDEV of OR
var LondonOR_line_lo05   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.maroon )      // Opening Range Low 0.5 STDEV of OR
var LondonOR_line_lo10   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 1.0 STDEV of OR
var LondonOR_line_lo15   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.5 STDEV of OR
var LondonOR_line_lo175  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.75 STDEV of OR
var LondonOR_line_lo20   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 2.0 STDEV of OR
var LondonOR_line_lo225  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.25 STDEV of OR
var LondonOR_line_lo25   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.5 STDEV of OR
var LondonOR_line_lo30   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 3.0 STDEV of OR
var LondonORBox          = box.new(left=LondonORStart, top=na, right=LondonOREnd, bottom=na, xloc=xloc.bar_time, border_width=2, border_color=color.new(i_LondonSessionCol, 100), bgcolor=color.new(i_LondonSessionCol, 70))
var LondonORLabel        = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelHigh    = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelHigh05  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelHigh10  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelHigh20  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelHigh30  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelLow     = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelLow05   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelLow10   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelLow20   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelLow30   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var LondonORLabelMid     = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
// ***
// New York Session
var float NewYork_hi = na        // High for the NewYork Session
var float NewYork_75 = na        // 75% level for the NewYork Session
var float NewYork_50 = na        // 50% level for the NewYork Session
var float NewYork_25 = na        // 25% level for the NewYork Session
var float NewYork_lo = na        // Low for the NewYork Session
var NewYork_line_hi  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYLevelCol)     // NewYork High line
var NewYork_line_75  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYLevelCol)     // NewYork 75% line
var NewYork_line_50  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYLevelCol)     // NewYork 50% line
var NewYork_line_25  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYLevelCol)     // NewYork 25% line
var NewYork_line_lo  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYLevelCol)     // NewYork Low line
var NewYorkHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYork75Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYork50Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYork25Label   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkLowLabel  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkSessionStart = time    // To register the timestap when the NewYork Session begins
var NewYorkORStart   = NewYorkSessionStart + (i_NewYorkORoffset * 60000) // Add the offset in milliseconds
var NewYorkOREnd     = NewYorkORStart + 3600000 // Add one hour in milliseconds
// NewYork Opening Range (1st Hour)
var float NewYorkHr1hi     = na       // High for the 1st Hour Session
var float NewYorkHr1mid    = na       // 50% of the 1st Hour Session
var float NewYorkHr1lo     = na       // Low for the 1st Hour Session
var NewYorkOR_line_hi     = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYSessionCol) // Opening Range High
var NewYorkOR_line_mid    = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYSessionCol) // Opening Range Middle
var NewYorkOR_line_lo     = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYSessionCol) // Opening Range Low
var NewYorkOR_line_hi05   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.teal)        // Opening Range High 0.5 STDEV of OR
var NewYorkOR_line_hi10   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 1.0 STDEV of OR
var NewYorkOR_line_hi15   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.5 STDEV of OR
var NewYorkOR_line_hi175  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.75 STDEV of OR
var NewYorkOR_line_hi20   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 2.0 STDEV of OR
var NewYorkOR_line_hi225  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.25 STDEV of OR
var NewYorkOR_line_hi25   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.5 STDEV of OR
var NewYorkOR_line_hi30   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 3.0 STDEV of OR
var NewYorkOR_line_lo05   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.maroon)          // Opening Range Low 0.5 STDEV of OR
var NewYorkOR_line_lo10   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 1.0 STDEV of OR
var NewYorkOR_line_lo15   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.5 STDEV of OR
var NewYorkOR_line_lo175  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.75 STDEV of OR
var NewYorkOR_line_lo20   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 2.0 STDEV of OR
var NewYorkOR_line_lo225  = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.25 STDEV of OR
var NewYorkOR_line_lo25   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.5 STDEV of OR
var NewYorkOR_line_lo30   = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 3.0 STDEV of OR
var NewYorkORBox          = box.new(left=NewYorkORStart, top=na, right=NewYorkOREnd, bottom=na, xloc=xloc.bar_time, border_width=2, border_color=color.new(i_NYSessionCol, 100), bgcolor=color.new(i_NYSessionCol, 70))
var NewYorkORLabelHigh    = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelHigh05  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelHigh10  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelHigh20  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelHigh30  = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelLow     = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelLow05   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelLow10   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelLow20   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelLow30   = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
var NewYorkORLabelMid     = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
// ***

// Create Labels
// Create initial Debug label
l_debug = label.new(x=na, y=na, text="Debug")
label.set_text(l_debug, "D")
label.set_color(l_debug, color=color.new(color.green, 60))
label.set_textcolor(l_debug, color.white)
label.set_yloc(l_debug, yloc.abovebar)
label.set_style(l_debug, label.style_label_down)
label.set_size(l_debug, size.tiny)

// ***


// 
// ALERTS Configuration for use during NY Session
//
// Function to trigger alerts when price crosses the Globex / Overnight Low during the NY Session
f_triggerGlobexLow()=>
    _co = ta.crossover(close, Globex_lo)
    _cu = ta.crossunder(close, Globex_lo)
    if _co and NewYorkSession and enableNewYorkalarms
        alert("Price (" + str.tostring(close) + ") crossing over Globex Low (" + str.tostring(Globex_lo) + ")", alert.freq_once_per_bar)
    else if _cu and NewYorkSession
        alert("Price (" + str.tostring(close) + ") crossing under Globex Low (" + str.tostring(Globex_lo) + ")", alert.freq_once_per_bar)
//

// Function to trigger alerts when price crosses the Globex / Overnight High during the NY Session
f_triggerGlobexHigh()=>
    _co = ta.crossover(close, Globex_hi)
    _cu = ta.crossunder(close, Globex_hi)
    if _co and NewYorkSession and enableNewYorkalarms
        alert("Price (" + str.tostring(close) + ") crossing over Globex High (" + str.tostring(Globex_hi) + ")", alert.freq_once_per_bar)
    else if _cu and NewYorkSession
        alert("Price (" + str.tostring(close) + ") crossing under Globex High (" + str.tostring(Globex_hi) + ")", alert.freq_once_per_bar)
//

// Function to trigger alerts when price crosses the NY Opening Range 50% level during the NY Session
f_triggerNewYorkOR50perc()=>
    _NewYorkOR50perc = (NewYorkHr1lo+(NewYorkHr1hi-NewYorkHr1lo)/2)
    _co = ta.crossover(close, _NewYorkOR50perc)
    _cu = ta.crossunder(close, _NewYorkOR50perc)
    if _co and NewYorkSession and time > NewYorkOREnd  and enableNewYorkalarms
        alert("Price (" + str.tostring(close) + ") crossing over NY OR 50% (" + str.tostring(_NewYorkOR50perc) + ")", alert.freq_once_per_bar)
    else if _cu and NewYorkSession and time > NewYorkOREnd
        alert("Price (" + str.tostring(close) + ") crossing under NY OR 50% (" + str.tostring(_NewYorkOR50perc) + ")", alert.freq_once_per_bar)
//

// Function to trigger alerts when price crosses the NY Opening Range STDEV 0.5 level during the NY Session
f_triggerNewYorkSTDEVpos05()=>
    _NewYorkSTDEVpos05=(NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)/2)
    _co = ta.crossover(close, _NewYorkSTDEVpos05)
    _cu = ta.crossunder(close, _NewYorkSTDEVpos05)
    if _co and NewYorkSession and time > NewYorkOREnd and enableNewYorkalarms
        alert("Price (" + str.tostring(close) + ") crossing over NY STDEV 0.5 (" + str.tostring(_NewYorkSTDEVpos05) + ")", alert.freq_once_per_bar)
    else if _cu and NewYorkSession and time > NewYorkOREnd
        alert("Price (" + str.tostring(close) + ") crossing under NY STDEV 0.5 (" + str.tostring(_NewYorkSTDEVpos05) + ")", alert.freq_once_per_bar)
//
// Function to trigger alerts when price crosses the NY Opening Range STDEV 1.0 level during the NY Session
f_triggerNewYorkSTDEVpos10()=>
    _NewYorkSTDEVpos10=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)
    _co = ta.crossover(close, _NewYorkSTDEVpos10)
    _cu = ta.crossunder(close, _NewYorkSTDEVpos10)
    if _co and NewYorkSession and time > NewYorkOREnd and enableNewYorkalarms
        alert("Price (" + str.tostring(close) + ") crossing over NY STDEV 1.0 (" + str.tostring(_NewYorkSTDEVpos10) + ")", alert.freq_once_per_bar)
    else if _cu and NewYorkSession and time > NewYorkOREnd
        alert("Price (" + str.tostring(close) + ") crossing under NY STDEV 1.0 (" + str.tostring(_NewYorkSTDEVpos10) + ")", alert.freq_once_per_bar)
//
// Function to trigger alerts when price crosses the NY Opening Range STDEV 0.5 level during the NY Session
f_triggerNewYorkSTDEVneg05()=>
    _NewYorkSTDEVneg05=(NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)/2)
    _co = ta.crossover(close, _NewYorkSTDEVneg05)
    _cu = ta.crossunder(close, _NewYorkSTDEVneg05)
    if _co and NewYorkSession and time > NewYorkOREnd and enableNewYorkalarms
        alert("Price (" + str.tostring(close) + ") crossing over NY STDEV -0.5 (" + str.tostring(_NewYorkSTDEVneg05) + ")", alert.freq_once_per_bar)
    else if _cu and NewYorkSession and time > NewYorkOREnd
        alert("Price (" + str.tostring(close) + ") crossing under NY STDEV -0.5 (" + str.tostring(_NewYorkSTDEVneg05) + ")", alert.freq_once_per_bar)
//
// Function to trigger alerts when price crosses the NY Opening Range STDEV 1.0 level during the NY Session
f_triggerNewYorkSTDEVneg10()=>
    _NewYorkSTDEVneg10=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)
    _co = ta.crossover(close, _NewYorkSTDEVneg10)
    _cu = ta.crossunder(close, _NewYorkSTDEVneg10)
    if _co and NewYorkSession and time > NewYorkOREnd and enableNewYorkalarms
        alert("Price (" + str.tostring(close) + ") crossing over NY STDEV -1.0 (" + str.tostring(_NewYorkSTDEVneg10) + ")", alert.freq_once_per_bar)
    else if _cu and NewYorkSession and time > NewYorkOREnd
        alert("Price (" + str.tostring(close) + ") crossing under NY STDEV -1.0 (" + str.tostring(_NewYorkSTDEVneg10) + ")", alert.freq_once_per_bar)
//
// End of Alert functions
// ***

// Function for determining the Start of a Session (taken from the Pinescript manual: https://www.tradingview.com/pine-script-docs/en/v5/concepts/Sessions.html )
sessionBegins(sess) =>
    t = time("", sess , i_timezone)
    timeframe.isintraday and (not barstate.isfirst) and na(t[1]) and not na(t)
// End function


// Start Logic
//bool isNewDate = ta.change(time("D"))   // Determine if new day has started. This is used to create new lines and labels.


// *** Here the actual sessions begin:
//
// Begin Globex Session Code
if sessionBegins(i_GlobexSession) // When a new Globex Session is started
    GlobexSessionStart := time   // Store the Session Starting timestamp
    CashSessionEndTime  := timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
    if CashSessionEndTime < GlobexSessionStart  // If the CashSessionEndTime is in the past, then add 1 day
        CashSessionEndTime := CashSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
    // We are entering Globex Session hours; reset hi/lo.
    Globex_hi       := srcHi
    Globex_lo       := srcLo
    Globex_75 := Globex_lo+(Globex_hi-Globex_lo)*0.75
    Globex_50 := Globex_lo+(Globex_hi-Globex_lo)*0.5
    Globex_25 := Globex_lo+(Globex_hi-Globex_lo)*0.25
    // Initialize the drawings for today
    if showGlobexDrawings
        // Keep or Remove all historic levels
        if showGlobexTodayDraw  // If true then delete all old objects
            line.delete(Globex_line_hi[1])
            line.delete(Globex_line_75[1])
            line.delete(Globex_line_50[1])
            line.delete(Globex_line_25[1])
            line.delete(Globex_line_lo[1])
            label.delete(GlobexHighLabel[1])
            label.delete(Globex75Label[1])
            label.delete(Globex50Label[1])
            label.delete(Globex25Label[1])
            label.delete(GlobexLowLabel[1])
        // Create new objects for today
        Globex_line_hi  := line.new(x1=GlobexSessionStart, y1=Globex_hi, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Globex_hi, color=i_GlobexLevelCol)    // Globex High line
        Globex_line_75  := line.new(x1=GlobexSessionStart, y1=Globex_75, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Globex_75, color=i_GlobexLevelCol)    // Globex 75% line
        Globex_line_50  := line.new(x1=GlobexSessionStart, y1=Globex_50, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Globex_50, color=i_GlobexLevelCol)    // Globex 50% line
        Globex_line_25  := line.new(x1=GlobexSessionStart, y1=Globex_25, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Globex_25, color=i_GlobexLevelCol)    // Globex 25% line
        Globex_line_lo  := line.new(x1=GlobexSessionStart, y1=Globex_lo, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Globex_lo, color=i_GlobexLevelCol)    // Globex Low line
        GlobexHighLabel := label.new(x=GlobexSessionStart, y=Globex_hi, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        Globex75Label   := label.new(x=GlobexSessionStart, y=Globex_75, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        Globex50Label   := label.new(x=GlobexSessionStart, y=Globex_50, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        Globex25Label   := label.new(x=GlobexSessionStart, y=Globex_25, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        GlobexLowLabel  := label.new(x=GlobexSessionStart, y=Globex_lo, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        label.set_tooltip(GlobexHighLabel, "Globex High")
        label.set_tooltip(Globex75Label, "Globex 75%")
        label.set_tooltip(Globex50Label, "Globex 50%")
        label.set_tooltip(Globex25Label, "Globex 25%")
        label.set_tooltip(GlobexLowLabel, "Globex Low")
else if GlobexSession
    // We are in allowed GlobexSession hours; track hi/lo.
    Globex_hi := math.max(srcHi, Globex_hi)
    Globex_lo := math.min(srcLo, Globex_lo)
    if (Globex_hi > Globex_hi[1])
        Globex_75 := Globex_lo+(Globex_hi-Globex_lo)*0.75
        Globex_50 := Globex_lo+(Globex_hi-Globex_lo)*0.5
        Globex_25 := Globex_lo+(Globex_hi-Globex_lo)*0.25
        if showGlobexDrawings
            line.set_xy1(id=Globex_line_hi, x=time, y=Globex_hi)
            line.set_xy2(id=Globex_line_hi, x=CashSessionEndTime, y=Globex_hi)
            line.set_xy1(id=Globex_line_75, x=GlobexSessionStart, y=Globex_75)
            line.set_xy2(id=Globex_line_75, x=CashSessionEndTime, y=Globex_75)
            line.set_xy1(id=Globex_line_50, x=GlobexSessionStart, y=Globex_50)
            line.set_xy2(id=Globex_line_50, x=CashSessionEndTime, y=Globex_50)
            line.set_xy1(id=Globex_line_25, x=GlobexSessionStart, y=Globex_25)
            line.set_xy2(id=Globex_line_25, x=CashSessionEndTime, y=Globex_25)
            if showLabels
                label.set_xy(id=GlobexHighLabel, x=CashSessionEndTime, y=Globex_hi)
                label.set_xy(id=Globex75Label, x=CashSessionEndTime, y=Globex_75)
                label.set_xy(id=Globex50Label, x=CashSessionEndTime, y=Globex_50)
                label.set_xy(id=Globex25Label, x=CashSessionEndTime, y=Globex_25)
                label.set_xy(id=GlobexLowLabel, x=CashSessionEndTime, y=Globex_lo)
    if (Globex_lo < Globex_lo[1])
        Globex_75 := Globex_lo+(Globex_hi-Globex_lo)*0.75
        Globex_50 := Globex_lo+(Globex_hi-Globex_lo)*0.5
        Globex_25 := Globex_lo+(Globex_hi-Globex_lo)*0.25
        if showGlobexDrawings
            line.set_xy1(id=Globex_line_lo, x=time, y=Globex_lo)
            line.set_xy2(id=Globex_line_lo, x=CashSessionEndTime, y=Globex_lo)
            line.set_xy1(id=Globex_line_75, x=GlobexSessionStart, y=Globex_75)
            line.set_xy2(id=Globex_line_75, x=CashSessionEndTime, y=Globex_75)
            line.set_xy1(id=Globex_line_50, x=GlobexSessionStart, y=Globex_50)
            line.set_xy2(id=Globex_line_50, x=CashSessionEndTime, y=Globex_50)
            line.set_xy1(id=Globex_line_25, x=GlobexSessionStart, y=Globex_25)
            line.set_xy2(id=Globex_line_25, x=CashSessionEndTime, y=Globex_25)
            if showLabels
                label.set_xy(id=GlobexHighLabel, x=CashSessionEndTime, y=Globex_hi)
                label.set_xy(id=Globex75Label, x=CashSessionEndTime, y=Globex_75)
                label.set_xy(id=Globex50Label, x=CashSessionEndTime, y=Globex_50)
                label.set_xy(id=Globex25Label, x=CashSessionEndTime, y=Globex_25)
                label.set_xy(id=GlobexLowLabel, x=CashSessionEndTime, y=Globex_lo)
// END Globex Session Code
// ***

// Begin Asian Session Code
if sessionBegins(i_AsianSession) // When a new Asian Session is started
    AsianSessionStart := time    // Store the Session Starting timestamp
    CashSessionEndTime  := timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
    if CashSessionEndTime < AsianSessionStart  // If the CashSessionEndTime is in the past, then add 1 day
        CashSessionEndTime := CashSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
    AsianORStart   := AsianSessionStart // There is no offset like the NY session. 
    AsianOREnd     := AsianSessionStart + 3600000 // Add one hour in milliseconds
    // We are entering Asian Session hours; reset hi/lo.    
    Asian_hi       := srcHi
    Asian_lo       := srcLo
    Asian_75 := Asian_lo+(Asian_hi-Asian_lo)*0.75
    Asian_50 := Asian_lo+(Asian_hi-Asian_lo)*0.5
    Asian_25 := Asian_lo+(Asian_hi-Asian_lo)*0.25
    AsianHr1hi  := srcHi
    AsianHr1lo  := srcLo
    // Show debug info
    if showDebugLabels 
        label.set_xloc(l_debug, x=bar_index, xloc=xloc.bar_index)
        label.set_tooltip(l_debug, "AsianSessionStart: " + str.tostring(AsianSessionStart) + "\nCashSessionEndTime: " + str.tostring(CashSessionEndTime) + "\nAsianORStart: " + str.tostring(AsianORStart) + "\nAsianOREnd: " + str.tostring(AsianOREnd))
    // End of debug code
    // Initialize the drawings for today
    if showAsianDrawings
        // Keep or Remove all historic levels
        if showAsianTodayDraw  // If true then delete all old objects
            line.delete(Asian_line_hi[1])
            line.delete(Asian_line_75[1])
            line.delete(Asian_line_50[1])
            line.delete(Asian_line_25[1])
            line.delete(Asian_line_lo[1])
            label.delete(AsianHighLabel[1])
            label.delete(Asian75Label[1])
            label.delete(Asian50Label[1])
            label.delete(Asian25Label[1])
            label.delete(AsianLowLabel[1])
            if showAsianOR // Delete historic Opening Range objects
                box.delete(AsianORBox[1])
                line.delete(AsianOR_line_hi[1])
                line.delete(AsianOR_line_mid[1])
                line.delete(AsianOR_line_lo[1])
                label.delete(AsianORLabelHigh[1])
                label.delete(AsianORLabelLow[1])
                label.delete(AsianORLabelMid[1])
                if showAsianORStdev   // Delete historic Opening Range STDEV objects
                    label.delete(AsianORLabelHigh05[1])
                    label.delete(AsianORLabelHigh10[1])
                    label.delete(AsianORLabelHigh20[1])
                    label.delete(AsianORLabelHigh30[1])
                    label.delete(AsianORLabelLow05[1])
                    label.delete(AsianORLabelLow10[1])
                    label.delete(AsianORLabelLow20[1])
                    label.delete(AsianORLabelLow30[1])
                    line.delete(AsianOR_line_hi05[1])
                    line.delete(AsianOR_line_hi10[1])
                    line.delete(AsianOR_line_hi15[1])
                    line.delete(AsianOR_line_hi175[1])
                    line.delete(AsianOR_line_hi20[1])
                    line.delete(AsianOR_line_hi225[1])
                    line.delete(AsianOR_line_hi25[1])
                    line.delete(AsianOR_line_hi30[1])
                    line.delete(AsianOR_line_lo05[1])
                    line.delete(AsianOR_line_lo10[1])
                    line.delete(AsianOR_line_lo15[1])
                    line.delete(AsianOR_line_lo175[1])
                    line.delete(AsianOR_line_lo20[1])
                    line.delete(AsianOR_line_lo225[1])
                    line.delete(AsianOR_line_lo25[1])
                    line.delete(AsianOR_line_lo30[1])
        // Create new objects for today
        Asian_line_hi  := line.new(x1=AsianSessionStart, y1=Asian_hi, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Asian_hi, color=i_AsianLevelCol)    // Asian High line
        Asian_line_75  := line.new(x1=AsianSessionStart, y1=Asian_75, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Asian_75, color=i_AsianLevelCol)    // Asian 75% line
        Asian_line_50  := line.new(x1=AsianSessionStart, y1=Asian_50, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Asian_50, color=i_AsianLevelCol)    // Asian 50% line
        Asian_line_25  := line.new(x1=AsianSessionStart, y1=Asian_25, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Asian_25, color=i_AsianLevelCol)    // Asian 25% line
        Asian_line_lo  := line.new(x1=AsianSessionStart, y1=Asian_lo, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=Asian_lo, color=i_AsianLevelCol)    // Asian Low line
        AsianHighLabel := label.new(x=AsianSessionStart, y=Asian_hi, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        Asian75Label   := label.new(x=AsianSessionStart, y=Asian_75, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        Asian50Label   := label.new(x=AsianSessionStart, y=Asian_50, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        Asian25Label   := label.new(x=AsianSessionStart, y=Asian_25, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        AsianLowLabel  := label.new(x=AsianSessionStart, y=Asian_lo, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        label.set_tooltip(AsianHighLabel, "Asian High")
        label.set_tooltip(Asian75Label, "Asian 75%")
        label.set_tooltip(Asian50Label, "Asian 50%")
        label.set_tooltip(Asian25Label, "Asian 25%")
        label.set_tooltip(AsianLowLabel,"Asian Low")
        if showAsianOR
            // The Asian 1st hour Opening Range initialization
            // Create new drawing objects
            AsianOR_line_hi     := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianSessionCol) // Opening Range High
            AsianOR_line_mid    := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianSessionCol) // Opening Range Middle
            AsianOR_line_lo     := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianSessionCol) // Opening Range Low
            AsianORBox          := box.new(left=AsianSessionStart, top=na, right=AsianOREnd, bottom=na, xloc=xloc.bar_time, border_width=2, border_color=color.new(i_AsianSessionCol, 100), bgcolor=color.new(i_AsianSessionCol, 70))
            //AsianORLabel        := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            AsianORLabelHigh    := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            AsianORLabelLow     := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            AsianORLabelMid     := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            if showAsianORStdev
                AsianOR_line_hi05   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.teal)         // Opening Range High 0.5 STDEV of OR
                AsianOR_line_hi10   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 1.0 STDEV of OR
                AsianOR_line_hi15   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.5 STDEV of OR
                AsianOR_line_hi175  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.75 STDEV of OR
                AsianOR_line_hi20   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 2.0 STDEV of OR
                AsianOR_line_hi225  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.25 STDEV of OR
                AsianOR_line_hi25   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.5 STDEV of OR
                AsianOR_line_hi30   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 3.0 STDEV of OR
                AsianOR_line_lo05   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.maroon)       // Opening Range Low 0.5 STDEV of OR
                AsianOR_line_lo10   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 1.0 STDEV of OR
                AsianOR_line_lo15   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.5 STDEV of OR
                AsianOR_line_lo175  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.75 STDEV of OR
                AsianOR_line_lo20   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 2.0 STDEV of OR
                AsianOR_line_lo225  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.25 STDEV of OR
                AsianOR_line_lo25   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.5 STDEV of OR
                AsianOR_line_lo30   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 3.0 STDEV of OR
                AsianORLabelHigh05  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                AsianORLabelHigh10  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                AsianORLabelHigh20  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                AsianORLabelHigh30  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                AsianORLabelLow05   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                AsianORLabelLow10   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                AsianORLabelLow20   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                AsianORLabelLow30   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
else if AsianSession
    // We are in allowed Asian Session hours; track hi/lo.
    Asian_hi := math.max(srcHi, Asian_hi)
    Asian_lo := math.min(srcLo, Asian_lo)
    if (Asian_hi > Asian_hi[1])
        Asian_75 := Asian_lo+(Asian_hi-Asian_lo)*0.75
        Asian_50 := Asian_lo+(Asian_hi-Asian_lo)*0.5
        Asian_25 := Asian_lo+(Asian_hi-Asian_lo)*0.25
        if showAsianDrawings
            line.set_xy1(id=Asian_line_hi, x=time, y=Asian_hi)
            line.set_xy2(id=Asian_line_hi, x=CashSessionEndTime, y=Asian_hi)
            line.set_xy1(id=Asian_line_75, x=AsianSessionStart, y=Asian_75)
            line.set_xy2(id=Asian_line_75, x=CashSessionEndTime, y=Asian_75)
            line.set_xy1(id=Asian_line_50, x=AsianSessionStart, y=Asian_50)
            line.set_xy2(id=Asian_line_50, x=CashSessionEndTime, y=Asian_50)
            line.set_xy1(id=Asian_line_25, x=AsianSessionStart, y=Asian_25)
            line.set_xy2(id=Asian_line_25, x=CashSessionEndTime, y=Asian_25)
            if showLabels
                label.set_xy(id=AsianHighLabel, x=CashSessionEndTime, y=Asian_hi)
                label.set_xy(id=Asian75Label, x=CashSessionEndTime, y=Asian_75)
                label.set_xy(id=Asian50Label, x=CashSessionEndTime, y=Asian_50)
                label.set_xy(id=Asian25Label, x=CashSessionEndTime, y=Asian_25)
                label.set_xy(id=AsianLowLabel,x=CashSessionEndTime, y=Asian_lo)
    if (Asian_lo < Asian_lo[1])
        Asian_75 := Asian_lo+(Asian_hi-Asian_lo)*0.75
        Asian_50 := Asian_lo+(Asian_hi-Asian_lo)*0.5
        Asian_25 := Asian_lo+(Asian_hi-Asian_lo)*0.25
        if showAsianDrawings
            line.set_xy1(id=Asian_line_lo, x=time, y=Asian_lo)
            line.set_xy2(id=Asian_line_lo, x=CashSessionEndTime, y=Asian_lo)
            line.set_xy1(id=Asian_line_75, x=AsianSessionStart, y=Asian_75)
            line.set_xy2(id=Asian_line_75, x=CashSessionEndTime, y=Asian_75)
            line.set_xy1(id=Asian_line_50, x=AsianSessionStart, y=Asian_50)
            line.set_xy2(id=Asian_line_50, x=CashSessionEndTime, y=Asian_50)
            line.set_xy1(id=Asian_line_25, x=AsianSessionStart, y=Asian_25)
            line.set_xy2(id=Asian_line_25, x=CashSessionEndTime, y=Asian_25)
            if showLabels
                label.set_xy(id=AsianHighLabel, x=CashSessionEndTime, y=Asian_hi)
                label.set_xy(id=Asian75Label, x=CashSessionEndTime, y=Asian_75)
                label.set_xy(id=Asian50Label, x=CashSessionEndTime, y=Asian_50)
                label.set_xy(id=Asian25Label, x=CashSessionEndTime, y=Asian_25)
                label.set_xy(id=AsianLowLabel, x=CashSessionEndTime, y=Asian_lo)
    if showAsianOR and (time >= AsianSessionStart and time <= AsianOREnd) // If the Opening Range is active
        // Calculate and Store the OR High and 50% - Needed for Alerts and Box drawing
        AsianHr1hi := math.max(srcHi, AsianHr1hi)
        AsianHr1lo := math.min(srcLo, AsianHr1lo)
        AsianHr1mid := AsianHr1lo+(AsianHr1hi-AsianHr1lo)*0.5
        // Show debug info
        if showDebugLabels 
            label.set_xloc(l_debug, x=bar_index, xloc=xloc.bar_index)
            label.set_tooltip(l_debug, "AsianSessionStart: " + str.tostring(AsianSessionStart) + "\nCurrentBartime: " + str.tostring(time) + "\nAsianORStart: " + str.tostring(AsianORStart) + "\nAsianOREnd: " + str.tostring(AsianOREnd) + "\nAsianHr1hi: " + str.tostring(AsianHr1hi) + "\nAsianHr1lo: " + str.tostring(AsianHr1lo))
        // End of debug code
        if (AsianHr1hi > AsianHr1hi[1])
            // Plot the 1st Hour Box
            box.set_lefttop(id=AsianORBox, left=AsianSessionStart, top=AsianHr1hi) 
            box.set_rightbottom(id=AsianORBox, right=AsianOREnd, bottom=AsianHr1lo)
            // Plot the 1st Hour hi/low Levels
            line.set_xy1(id=AsianOR_line_hi, x=AsianSessionStart, y=AsianHr1hi)
            line.set_xy2(id=AsianOR_line_hi, x=CashSessionEndTime, y=AsianHr1hi)
            line.set_xy1(id=AsianOR_line_mid, x=AsianOREnd, y=AsianHr1mid)
            line.set_xy2(id=AsianOR_line_mid, x=CashSessionEndTime, y=AsianHr1mid)
            line.set_xy1(id=AsianOR_line_lo, x=AsianSessionStart, y=AsianHr1lo)
            line.set_xy2(id=AsianOR_line_lo, x=CashSessionEndTime,  y=AsianHr1lo)
            if showLabels
                label.set_text(id=AsianORLabelHigh, text="OR High")
                label.set_xy(id=AsianORLabelHigh, x=CashSessionEndTime, y=AsianHr1hi)
                label.set_text(id=AsianORLabelMid, text="OR 50%")
                label.set_xy(id=AsianORLabelMid, x=CashSessionEndTime, y=AsianHr1mid)
                label.set_text(id=AsianORLabelLow, text="OR Low")
                label.set_xy(id=AsianORLabelLow, x=CashSessionEndTime, y=AsianHr1lo)
        if (AsianHr1lo < AsianHr1lo[1])
            // Plot the 1st Hour Box
            box.set_lefttop(id=AsianORBox, left=AsianSessionStart, top=AsianHr1hi) 
            box.set_rightbottom(id=AsianORBox, right=AsianOREnd, bottom=AsianHr1lo)
            // Plot the 1st Hour hi/low Levels
            line.set_xy1(id=AsianOR_line_hi, x=AsianSessionStart, y=AsianHr1hi)
            line.set_xy2(id=AsianOR_line_hi, x=CashSessionEndTime, y=AsianHr1hi)
            line.set_xy1(id=AsianOR_line_mid, x=AsianOREnd, y=AsianHr1mid)
            line.set_xy2(id=AsianOR_line_mid, x=CashSessionEndTime, y=AsianHr1mid)
            line.set_xy1(id=AsianOR_line_lo, x=AsianSessionStart, y=AsianHr1lo)
            line.set_xy2(id=AsianOR_line_lo, x=CashSessionEndTime,  y=AsianHr1lo)
            if showLabels
                label.set_text(id=AsianORLabelHigh, text="OR High")
                label.set_xy(id=AsianORLabelHigh, x=CashSessionEndTime, y=AsianHr1hi)
                label.set_text(id=AsianORLabelMid, text="OR 50%")
                label.set_xy(id=AsianORLabelMid, x=CashSessionEndTime, y=AsianHr1mid)
                label.set_text(id=AsianORLabelLow, text="OR Low")
                label.set_xy(id=AsianORLabelLow, x=CashSessionEndTime, y=AsianHr1lo)
    if showAsianOR and time == AsianOREnd and showAsianORStdev // (At the exact end of Asian OR, calculate and draw the STDev levels )
        // Plot the Positive IB STDEVs
        line.set_xy1(id=AsianOR_line_hi05, x=AsianOREnd+1000000, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*0.5)
        line.set_xy2(id=AsianOR_line_hi05, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*0.5)
        line.set_xy1(id=AsianOR_line_hi10, x=AsianOREnd+1800000, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo))
        line.set_xy2(id=AsianOR_line_hi10, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo))
        line.set_xy1(id=AsianOR_line_hi15, x=AsianOREnd+3600000, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*1.5)
        line.set_xy2(id=AsianOR_line_hi15, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*1.5)
        line.set_xy1(id=AsianOR_line_hi175, x=AsianOREnd+5000000, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*1.75)
        line.set_xy2(id=AsianOR_line_hi175, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*1.75)
        line.set_xy1(id=AsianOR_line_hi20, x=AsianOREnd+7200000, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*2)
        line.set_xy2(id=AsianOR_line_hi20, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*2)
        line.set_xy1(id=AsianOR_line_hi225, x=AsianOREnd+8800000, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*2.25)
        line.set_xy2(id=AsianOR_line_hi225, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*2.25)
        line.set_xy1(id=AsianOR_line_hi25, x=AsianOREnd+10800000, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*2.5)
        line.set_xy2(id=AsianOR_line_hi25, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*2.5)
        line.set_xy1(id=AsianOR_line_hi30, x=AsianOREnd+12800000, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*3)
        line.set_xy2(id=AsianOR_line_hi30, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*3)
        // Plot the Negative IB STDEVs
        line.set_xy1(id=AsianOR_line_lo05, x=AsianOREnd+1000000, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*0.5)
        line.set_xy2(id=AsianOR_line_lo05, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*0.5)
        line.set_xy1(id=AsianOR_line_lo10, x=AsianOREnd+1800000, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo))
        line.set_xy2(id=AsianOR_line_lo10, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo))
        line.set_xy1(id=AsianOR_line_lo15, x=AsianOREnd+3600000, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*1.5)
        line.set_xy2(id=AsianOR_line_lo15, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*1.5)
        line.set_xy1(id=AsianOR_line_lo175, x=AsianOREnd+5000000, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*1.75)
        line.set_xy2(id=AsianOR_line_lo175, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*1.75)
        line.set_xy1(id=AsianOR_line_lo20, x=AsianOREnd+7200000, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*2)
        line.set_xy2(id=AsianOR_line_lo20, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*2)
        line.set_xy1(id=AsianOR_line_lo225, x=AsianOREnd+8800000, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*2.25)
        line.set_xy2(id=AsianOR_line_lo225, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*2.25)
        line.set_xy1(id=AsianOR_line_lo25, x=AsianOREnd+10800000, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*2.5)
        line.set_xy2(id=AsianOR_line_lo25, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*2.5)
        line.set_xy1(id=AsianOR_line_lo30, x=AsianOREnd+12800000, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*3)
        line.set_xy2(id=AsianOR_line_lo30, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*3)
        // Plot the IB STDEV Labels
        if showLabels
            label.set_text(id=AsianORLabelHigh05, text="0.5 OR")
            label.set_xy(id=AsianORLabelHigh05, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)/2)
            label.set_text(id=AsianORLabelHigh10, text="1.0 OR")
            label.set_xy(id=AsianORLabelHigh10, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo))
            label.set_text(id=AsianORLabelHigh20, text="2.0 OR")
            label.set_xy(id=AsianORLabelHigh20, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*2)
            label.set_text(id=AsianORLabelHigh30, text="3.0 OR")
            label.set_xy(id=AsianORLabelHigh30, x=CashSessionEndTime, y=AsianHr1hi+(AsianHr1hi-AsianHr1lo)*3)
            label.set_text(id=AsianORLabelLow05, text="-0.5 OR")
            label.set_xy(id=AsianORLabelLow05, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)/2)
            label.set_text(id=AsianORLabelLow10, text="-1.0 OR")
            label.set_xy(id=AsianORLabelLow10, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo))
            label.set_text(id=AsianORLabelLow20, text="-2.0 OR")
            label.set_xy(id=AsianORLabelLow20, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*2)
            label.set_text(id=AsianORLabelLow30, text="-3.0 OR")
            label.set_xy(id=AsianORLabelLow30, x=CashSessionEndTime, y=AsianHr1lo-(AsianHr1hi-AsianHr1lo)*3)
// END Asian Session Code
// ***



// Begin London Session Code
if sessionBegins(i_LondonSession) // When a new London Session is started
    LondonSessionStart := time    // Store the Session Starting timestamp
    CashSessionEndTime  := timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
    if CashSessionEndTime < LondonSessionStart  // If the CashSessionEndTime is in the past, then add 1 day
        CashSessionEndTime := CashSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
    LondonORStart   := LondonSessionStart // No offset needed here, like in the NY session.
    LondonOREnd     := LondonORStart + 3600000 // Add one hour in milliseconds
    // We are entering London Session hours; reset hi/lo.    
    London_hi       := srcHi
    London_lo       := srcLo
    London_75 := London_lo+(London_hi-London_lo)*0.75
    London_50 := London_lo+(London_hi-London_lo)*0.5
    London_25 := London_lo+(London_hi-London_lo)*0.25
    // Reset the Hr1 price tracking vars
    LondonHr1hi  := srcHi
    LondonHr1lo  := srcLo
    // Show debug info
    if showDebugLabels 
        label.set_xloc(l_debug, x=bar_index, xloc=xloc.bar_index)
        label.set_tooltip(l_debug, "LondonSessionStart: " + str.tostring(LondonSessionStart) + "\nCashSessionEndTime: " + str.tostring(CashSessionEndTime) + "\nLondonORStart: " + str.tostring(LondonORStart) 
         + "\nLondonOREnd: " + str.tostring(LondonOREnd) + "\nLondonHr1hi: " + str.tostring(LondonHr1hi) + "\nLondonHr1lo: " + str.tostring(LondonHr1lo))
    // End of debug code
    // Initialize the drawings for today
    if showLondonDrawings
        // Keep or Remove all historic levels
        if showLondonTodayDraw  // If true then delete all old objects
            line.delete(London_line_hi[1])
            line.delete(London_line_75[1])
            line.delete(London_line_50[1])
            line.delete(London_line_25[1])
            line.delete(London_line_lo[1])
            label.delete(LondonHighLabel[1])
            label.delete(London75Label[1])
            label.delete(London50Label[1])
            label.delete(London25Label[1])
            label.delete(LondonLowLabel[1])
            if showLondonOR // Delete historic Opening Range objects
                box.delete(LondonORBox[1])
                line.delete(LondonOR_line_hi[1])
                line.delete(LondonOR_line_mid[1])
                line.delete(LondonOR_line_lo[1])
                label.delete(LondonORLabelHigh[1])
                label.delete(LondonORLabelLow[1])
                label.delete(LondonORLabelMid[1])
                if showLondonORStdev   // Delete historic Opening Range STDEV objects
                    label.delete(LondonORLabelHigh05[1])
                    label.delete(LondonORLabelHigh10[1])
                    label.delete(LondonORLabelHigh20[1])
                    label.delete(LondonORLabelHigh30[1])
                    label.delete(LondonORLabelLow05[1])
                    label.delete(LondonORLabelLow10[1])
                    label.delete(LondonORLabelLow20[1])
                    label.delete(LondonORLabelLow30[1])
                    line.delete(LondonOR_line_hi05[1])
                    line.delete(LondonOR_line_hi10[1])
                    line.delete(LondonOR_line_hi15[1])
                    line.delete(LondonOR_line_hi175[1])
                    line.delete(LondonOR_line_hi20[1])
                    line.delete(LondonOR_line_hi225[1])
                    line.delete(LondonOR_line_hi25[1])
                    line.delete(LondonOR_line_hi30[1])
                    line.delete(LondonOR_line_lo05[1])
                    line.delete(LondonOR_line_lo10[1])
                    line.delete(LondonOR_line_lo15[1])
                    line.delete(LondonOR_line_lo175[1])
                    line.delete(LondonOR_line_lo20[1])
                    line.delete(LondonOR_line_lo225[1])
                    line.delete(LondonOR_line_lo25[1])
                    line.delete(LondonOR_line_lo30[1])
        // Create new objects for today
        London_line_hi  := line.new(x1=LondonSessionStart, y1=London_hi, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=London_hi, color=i_NYLevelCol)    // London High line
        London_line_75  := line.new(x1=LondonSessionStart, y1=London_75, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=London_75, color=i_NYLevelCol)    // London 75% line
        London_line_50  := line.new(x1=LondonSessionStart, y1=London_50, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=London_50, color=i_NYLevelCol)    // London 50% line
        London_line_25  := line.new(x1=LondonSessionStart, y1=London_25, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=London_25, color=i_NYLevelCol)    // London 25% line
        London_line_lo  := line.new(x1=LondonSessionStart, y1=London_lo, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=London_lo, color=i_NYLevelCol)    // London Low line
        LondonHighLabel := label.new(x=LondonSessionStart, y=London_hi, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        London75Label   := label.new(x=LondonSessionStart, y=London_75, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        London50Label   := label.new(x=LondonSessionStart, y=London_50, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        London25Label   := label.new(x=LondonSessionStart, y=London_25, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        LondonLowLabel  := label.new(x=LondonSessionStart, y=London_lo, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        label.set_tooltip(LondonHighLabel, "London High")
        label.set_tooltip(London75Label, "London 75%")
        label.set_tooltip(London50Label, "London 50%")
        label.set_tooltip(London25Label, "London 25%")
        label.set_tooltip(LondonLowLabel,"London Low")
        if showLondonOR
            // The London 1st hour Opening Range initialization
            // Create new drawing objects
            LondonOR_line_hi     := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonSessionCol) // Opening Range High
            LondonOR_line_mid    := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonSessionCol) // Opening Range Middle
            LondonOR_line_lo     := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonSessionCol) // Opening Range Low
            LondonORBox          := box.new(left=LondonORStart, top=na, right=LondonOREnd, bottom=na, xloc=xloc.bar_time, border_width=2, border_color=color.new(i_LondonSessionCol, 100), bgcolor=color.new(i_LondonSessionCol, 70))
            //LondonORLabel        := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            LondonORLabelHigh    := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            LondonORLabelLow     := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            LondonORLabelMid     := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            if showLondonORStdev
                LondonOR_line_hi05   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.teal)         // Opening Range High 0.5 STDEV of OR
                LondonOR_line_hi10   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 1.0 STDEV of OR
                LondonOR_line_hi15   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.5 STDEV of OR
                LondonOR_line_hi175  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.75 STDEV of OR
                LondonOR_line_hi20   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 2.0 STDEV of OR
                LondonOR_line_hi225  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.25 STDEV of OR
                LondonOR_line_hi25   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.5 STDEV of OR
                LondonOR_line_hi30   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 3.0 STDEV of OR
                LondonOR_line_lo05   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.maroon)       // Opening Range Low 0.5 STDEV of OR
                LondonOR_line_lo10   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 1.0 STDEV of OR
                LondonOR_line_lo15   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.5 STDEV of OR
                LondonOR_line_lo175  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.75 STDEV of OR
                LondonOR_line_lo20   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 2.0 STDEV of OR
                LondonOR_line_lo225  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.25 STDEV of OR
                LondonOR_line_lo25   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.5 STDEV of OR
                LondonOR_line_lo30   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 3.0 STDEV of OR
                LondonORLabelHigh05  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                LondonORLabelHigh10  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                LondonORLabelHigh20  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                LondonORLabelHigh30  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                LondonORLabelLow05   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                LondonORLabelLow10   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                LondonORLabelLow20   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                LondonORLabelLow30   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
else if LondonSession
    // We are in allowed London Session hours; track hi/lo.
    London_hi := math.max(srcHi, London_hi)
    London_lo := math.min(srcLo, London_lo)
    if (London_hi > London_hi[1])
        London_75 := London_lo+(London_hi-London_lo)*0.75
        London_50 := London_lo+(London_hi-London_lo)*0.5
        London_25 := London_lo+(London_hi-London_lo)*0.25
        if showLondonDrawings
            line.set_xy1(id=London_line_hi, x=time, y=London_hi)
            line.set_xy2(id=London_line_hi, x=CashSessionEndTime, y=London_hi)
            line.set_xy1(id=London_line_75, x=LondonSessionStart, y=London_75)
            line.set_xy2(id=London_line_75, x=CashSessionEndTime, y=London_75)
            line.set_xy1(id=London_line_50, x=LondonSessionStart, y=London_50)
            line.set_xy2(id=London_line_50, x=CashSessionEndTime, y=London_50)
            line.set_xy1(id=London_line_25, x=LondonSessionStart, y=London_25)
            line.set_xy2(id=London_line_25, x=CashSessionEndTime, y=London_25)
            if showLabels
                label.set_xy(id=LondonHighLabel, x=CashSessionEndTime, y=London_hi)
                label.set_xy(id=London75Label, x=CashSessionEndTime, y=London_75)
                label.set_xy(id=London50Label, x=CashSessionEndTime, y=London_50)
                label.set_xy(id=London25Label, x=CashSessionEndTime, y=London_25)
                label.set_xy(id=LondonLowLabel,x=CashSessionEndTime, y=London_lo)
    if (London_lo < London_lo[1])
        London_75 := London_lo+(London_hi-London_lo)*0.75
        London_50 := London_lo+(London_hi-London_lo)*0.5
        London_25 := London_lo+(London_hi-London_lo)*0.25
        if showLondonDrawings
            line.set_xy1(id=London_line_lo, x=time, y=London_lo)
            line.set_xy2(id=London_line_lo, x=CashSessionEndTime, y=London_lo)
            line.set_xy1(id=London_line_75, x=LondonSessionStart, y=London_75)
            line.set_xy2(id=London_line_75, x=CashSessionEndTime, y=London_75)
            line.set_xy1(id=London_line_50, x=LondonSessionStart, y=London_50)
            line.set_xy2(id=London_line_50, x=CashSessionEndTime, y=London_50)
            line.set_xy1(id=London_line_25, x=LondonSessionStart, y=London_25)
            line.set_xy2(id=London_line_25, x=CashSessionEndTime, y=London_25)
            if showLabels
                label.set_xy(id=LondonHighLabel, x=CashSessionEndTime, y=London_hi)
                label.set_xy(id=London75Label, x=CashSessionEndTime, y=London_75)
                label.set_xy(id=London50Label, x=CashSessionEndTime, y=London_50)
                label.set_xy(id=London25Label, x=CashSessionEndTime, y=London_25)
                label.set_xy(id=LondonLowLabel, x=CashSessionEndTime, y=London_lo)
    if showLondonOR and time >= LondonORStart and time <= LondonOREnd // If the Opening Range is active
        // Calculate and Store the OR High and 50% - Needed for Alerts and Box drawing
        LondonHr1hi := math.max(srcHi, LondonHr1hi)
        LondonHr1lo := math.min(srcLo, LondonHr1lo)
        LondonHr1mid := LondonHr1lo+(LondonHr1hi-LondonHr1lo)*0.5
        // Show debug info
        if showDebugLabels 
            label.set_xloc(l_debug, x=bar_index, xloc=xloc.bar_index)
            label.set_tooltip(l_debug, "LondonSessionStart: " + str.tostring(LondonSessionStart) + "\nCashSessionEndTime: " + str.tostring(CashSessionEndTime) + "\nLondonORStart: " + str.tostring(LondonORStart) 
             + "\nLondonOREnd: " + str.tostring(LondonOREnd) + "\nLondonHr1hi: " + str.tostring(LondonHr1hi) + "\nLondonHr1lo: " + str.tostring(LondonHr1lo))
        // End of debug code
        if (LondonHr1hi > LondonHr1hi[1])
            // Plot the 1st Hour Box
            box.set_lefttop(id=LondonORBox, left=LondonORStart, top=LondonHr1hi) 
            box.set_rightbottom(id=LondonORBox, right=LondonOREnd, bottom=LondonHr1lo)
            // Plot the 1st Hour hi/low Levels
            line.set_xy1(id=LondonOR_line_hi, x=LondonORStart, y=LondonHr1hi)
            line.set_xy2(id=LondonOR_line_hi, x=CashSessionEndTime, y=LondonHr1hi)
            line.set_xy1(id=LondonOR_line_mid, x=LondonOREnd, y=LondonHr1mid)
            line.set_xy2(id=LondonOR_line_mid, x=CashSessionEndTime, y=LondonHr1mid)
            line.set_xy1(id=LondonOR_line_lo, x=LondonORStart, y=LondonHr1lo)
            line.set_xy2(id=LondonOR_line_lo, x=CashSessionEndTime,  y=LondonHr1lo)
            if showLabels
                label.set_text(id=LondonORLabelHigh, text="OR High")
                label.set_xy(id=LondonORLabelHigh, x=CashSessionEndTime, y=LondonHr1hi)
                label.set_text(id=LondonORLabelMid, text="OR 50%")
                label.set_xy(id=LondonORLabelMid, x=CashSessionEndTime, y=LondonHr1mid)
                label.set_text(id=LondonORLabelLow, text="OR Low")
                label.set_xy(id=LondonORLabelLow, x=CashSessionEndTime, y=LondonHr1lo)
        if (LondonHr1lo < LondonHr1lo[1])
            // Plot the 1st Hour Box
            box.set_lefttop(id=LondonORBox, left=LondonORStart, top=LondonHr1hi) 
            box.set_rightbottom(id=LondonORBox, right=LondonOREnd, bottom=LondonHr1lo)
            // Plot the 1st Hour hi/low Levels
            line.set_xy1(id=LondonOR_line_hi, x=LondonORStart, y=LondonHr1hi)
            line.set_xy2(id=LondonOR_line_hi, x=CashSessionEndTime, y=LondonHr1hi)
            line.set_xy1(id=LondonOR_line_mid, x=LondonOREnd, y=LondonHr1mid)
            line.set_xy2(id=LondonOR_line_mid, x=CashSessionEndTime, y=LondonHr1mid)
            line.set_xy1(id=LondonOR_line_lo, x=LondonORStart, y=LondonHr1lo)
            line.set_xy2(id=LondonOR_line_lo, x=CashSessionEndTime,  y=LondonHr1lo)
            if showLabels
                label.set_text(id=LondonORLabelHigh, text="OR High")
                label.set_xy(id=LondonORLabelHigh, x=CashSessionEndTime, y=LondonHr1hi)
                label.set_text(id=LondonORLabelMid, text="OR 50%")
                label.set_xy(id=LondonORLabelMid, x=CashSessionEndTime, y=LondonHr1mid)
                label.set_text(id=LondonORLabelLow, text="OR Low")
                label.set_xy(id=LondonORLabelLow, x=CashSessionEndTime, y=LondonHr1lo)
    if showLondonOR and time == LondonOREnd and showLondonORStdev // (At the exact end of London OR, calculate and draw the STDev levels )
        // Plot the Positive IB STDEVs
        line.set_xy1(id=LondonOR_line_hi05, x=LondonOREnd+1000000, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*0.5)
        line.set_xy2(id=LondonOR_line_hi05, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*0.5)
        line.set_xy1(id=LondonOR_line_hi10, x=LondonOREnd+1800000, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo))
        line.set_xy2(id=LondonOR_line_hi10, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo))
        line.set_xy1(id=LondonOR_line_hi15, x=LondonOREnd+3600000, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*1.5)
        line.set_xy2(id=LondonOR_line_hi15, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*1.5)
        line.set_xy1(id=LondonOR_line_hi175, x=LondonOREnd+5000000, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*1.75)
        line.set_xy2(id=LondonOR_line_hi175, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*1.75)
        line.set_xy1(id=LondonOR_line_hi20, x=LondonOREnd+7200000, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*2)
        line.set_xy2(id=LondonOR_line_hi20, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*2)
        line.set_xy1(id=LondonOR_line_hi225, x=LondonOREnd+8800000, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*2.25)
        line.set_xy2(id=LondonOR_line_hi225, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*2.25)
        line.set_xy1(id=LondonOR_line_hi25, x=LondonOREnd+10800000, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*2.5)
        line.set_xy2(id=LondonOR_line_hi25, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*2.5)
        line.set_xy1(id=LondonOR_line_hi30, x=LondonOREnd+12800000, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*3)
        line.set_xy2(id=LondonOR_line_hi30, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*3)
        // Plot the Negative IB STDEVs
        line.set_xy1(id=LondonOR_line_lo05, x=LondonOREnd+1000000, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*0.5)
        line.set_xy2(id=LondonOR_line_lo05, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*0.5)
        line.set_xy1(id=LondonOR_line_lo10, x=LondonOREnd+1800000, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo))
        line.set_xy2(id=LondonOR_line_lo10, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo))
        line.set_xy1(id=LondonOR_line_lo15, x=LondonOREnd+3600000, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*1.5)
        line.set_xy2(id=LondonOR_line_lo15, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*1.5)
        line.set_xy1(id=LondonOR_line_lo175, x=LondonOREnd+5000000, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*1.75)
        line.set_xy2(id=LondonOR_line_lo175, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*1.75)
        line.set_xy1(id=LondonOR_line_lo20, x=LondonOREnd+7200000, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*2)
        line.set_xy2(id=LondonOR_line_lo20, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*2)
        line.set_xy1(id=LondonOR_line_lo225, x=LondonOREnd+8800000, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*2.25)
        line.set_xy2(id=LondonOR_line_lo225, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*2.25)
        line.set_xy1(id=LondonOR_line_lo25, x=LondonOREnd+10800000, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*2.5)
        line.set_xy2(id=LondonOR_line_lo25, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*2.5)
        line.set_xy1(id=LondonOR_line_lo30, x=LondonOREnd+12800000, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*3)
        line.set_xy2(id=LondonOR_line_lo30, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*3)
        // Plot the IB STDEV Labels
        if showLabels
            label.set_text(id=LondonORLabelHigh05, text="0.5 OR")
            label.set_xy(id=LondonORLabelHigh05, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)/2)
            label.set_text(id=LondonORLabelHigh10, text="1.0 OR")
            label.set_xy(id=LondonORLabelHigh10, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo))
            label.set_text(id=LondonORLabelHigh20, text="2.0 OR")
            label.set_xy(id=LondonORLabelHigh20, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*2)
            label.set_text(id=LondonORLabelHigh30, text="3.0 OR")
            label.set_xy(id=LondonORLabelHigh30, x=CashSessionEndTime, y=LondonHr1hi+(LondonHr1hi-LondonHr1lo)*3)
            label.set_text(id=LondonORLabelLow05, text="-0.5 OR")
            label.set_xy(id=LondonORLabelLow05, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)/2)
            label.set_text(id=LondonORLabelLow10, text="-1.0 OR")
            label.set_xy(id=LondonORLabelLow10, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo))
            label.set_text(id=LondonORLabelLow20, text="-2.0 OR")
            label.set_xy(id=LondonORLabelLow20, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*2)
            label.set_text(id=LondonORLabelLow30, text="-3.0 OR")
            label.set_xy(id=LondonORLabelLow30, x=CashSessionEndTime, y=LondonHr1lo-(LondonHr1hi-LondonHr1lo)*3)
// END London Session Code
// ***


// Begin NewYork Session Code
if sessionBegins(i_NewYorkSession) // When a new NewYork Session is started
    NewYorkSessionStart := time    // Store the Session Starting timestamp
    CashSessionEndTime  := timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
    if CashSessionEndTime < NewYorkSessionStart  // If the CashSessionEndTime is in the past, then add 1 day
        CashSessionEndTime := CashSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
    NewYorkORStart   := NewYorkSessionStart + (i_NewYorkORoffset * 60000) // Add the offset in milliseconds
    NewYorkOREnd     := NewYorkORStart + 3600000 // Add one hour in milliseconds
    // We are entering NewYork Session hours; reset hi/lo.    
    NewYork_hi       := srcHi
    NewYork_lo       := srcLo
    NewYork_75 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.75
    NewYork_50 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.5
    NewYork_25 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.25
    // Initialize the drawings for today
    if showNewYorkDrawings
        // Keep or Remove all historic levels
        if showNewYorkTodayDraw  // If true then delete all old objects
            line.delete(NewYork_line_hi[1])
            line.delete(NewYork_line_75[1])
            line.delete(NewYork_line_50[1])
            line.delete(NewYork_line_25[1])
            line.delete(NewYork_line_lo[1])
            label.delete(NewYorkHighLabel[1])
            label.delete(NewYork75Label[1])
            label.delete(NewYork50Label[1])
            label.delete(NewYork25Label[1])
            label.delete(NewYorkLowLabel[1])
            if showNewYorkOR // Delete historic Opening Range objects
                box.delete(NewYorkORBox[1])
                line.delete(NewYorkOR_line_hi[1])
                line.delete(NewYorkOR_line_mid[1])
                line.delete(NewYorkOR_line_lo[1])
                label.delete(NewYorkORLabelHigh[1])
                label.delete(NewYorkORLabelLow[1])
                label.delete(NewYorkORLabelMid[1])
                if showNewYorkORStdev   // Delete historic Opening Range STDEV objects
                    label.delete(NewYorkORLabelHigh05[1])
                    label.delete(NewYorkORLabelHigh10[1])
                    label.delete(NewYorkORLabelHigh20[1])
                    label.delete(NewYorkORLabelHigh30[1])
                    label.delete(NewYorkORLabelLow05[1])
                    label.delete(NewYorkORLabelLow10[1])
                    label.delete(NewYorkORLabelLow20[1])
                    label.delete(NewYorkORLabelLow30[1])
                    line.delete(NewYorkOR_line_hi05[1])
                    line.delete(NewYorkOR_line_hi10[1])
                    line.delete(NewYorkOR_line_hi15[1])
                    line.delete(NewYorkOR_line_hi175[1])
                    line.delete(NewYorkOR_line_hi20[1])
                    line.delete(NewYorkOR_line_hi225[1])
                    line.delete(NewYorkOR_line_hi25[1])
                    line.delete(NewYorkOR_line_hi30[1])
                    line.delete(NewYorkOR_line_lo05[1])
                    line.delete(NewYorkOR_line_lo10[1])
                    line.delete(NewYorkOR_line_lo15[1])
                    line.delete(NewYorkOR_line_lo175[1])
                    line.delete(NewYorkOR_line_lo20[1])
                    line.delete(NewYorkOR_line_lo225[1])
                    line.delete(NewYorkOR_line_lo25[1])
                    line.delete(NewYorkOR_line_lo30[1])
        // Create new objects for today
        NewYork_line_hi  := line.new(x1=NewYorkSessionStart, y1=NewYork_hi, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=NewYork_hi, color=i_NYLevelCol)    // NewYork High line
        NewYork_line_75  := line.new(x1=NewYorkSessionStart, y1=NewYork_75, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=NewYork_75, color=i_NYLevelCol)    // NewYork 75% line
        NewYork_line_50  := line.new(x1=NewYorkSessionStart, y1=NewYork_50, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=NewYork_50, color=i_NYLevelCol)    // NewYork 50% line
        NewYork_line_25  := line.new(x1=NewYorkSessionStart, y1=NewYork_25, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=NewYork_25, color=i_NYLevelCol)    // NewYork 25% line
        NewYork_line_lo  := line.new(x1=NewYorkSessionStart, y1=NewYork_lo, x2=CashSessionEndTime, xloc=xloc.bar_time, y2=NewYork_lo, color=i_NYLevelCol)    // NewYork Low line
        NewYorkHighLabel := label.new(x=NewYorkSessionStart, y=NewYork_hi, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        NewYork75Label   := label.new(x=NewYorkSessionStart, y=NewYork_75, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        NewYork50Label   := label.new(x=NewYorkSessionStart, y=NewYork_50, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        NewYork25Label   := label.new(x=NewYorkSessionStart, y=NewYork_25, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        NewYorkLowLabel  := label.new(x=NewYorkSessionStart, y=NewYork_lo, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
        label.set_tooltip(NewYorkHighLabel, "New York High")
        label.set_tooltip(NewYork75Label, "New York 75%")
        label.set_tooltip(NewYork50Label, "New York 50%")
        label.set_tooltip(NewYork25Label, "New York 25%")
        label.set_tooltip(NewYorkLowLabel,"New York Low")
        if showNewYorkOR
            // The NewYork 1st hour Opening Range initialization
            // Create new drawing objects
            NewYorkOR_line_hi     := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYSessionCol) // Opening Range High
            NewYorkOR_line_mid    := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYSessionCol) // Opening Range Middle
            NewYorkOR_line_lo     := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYSessionCol) // Opening Range Low
            NewYorkORBox          := box.new(left=NewYorkORStart, top=na, right=NewYorkOREnd, bottom=na, xloc=xloc.bar_time, border_width=2, border_color=color.new(i_NYSessionCol, 100), bgcolor=color.new(i_NYSessionCol, 70))
            //NewYorkORLabel        := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            NewYorkORLabelHigh    := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            NewYorkORLabelLow     := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            NewYorkORLabelMid     := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
            if showNewYorkORStdev
                NewYorkOR_line_hi05   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.teal)         // Opening Range High 0.5 STDEV of OR
                NewYorkOR_line_hi10   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 1.0 STDEV of OR
                NewYorkOR_line_hi15   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.5 STDEV of OR
                NewYorkOR_line_hi175  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 1.75 STDEV of OR
                NewYorkOR_line_hi20   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 2.0 STDEV of OR
                NewYorkOR_line_hi225  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.25 STDEV of OR
                NewYorkOR_line_hi25   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range High 2.5 STDEV of OR
                NewYorkOR_line_hi30   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.green)        // Opening Range High 3.0 STDEV of OR
                NewYorkOR_line_lo05   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.maroon)       // Opening Range Low 0.5 STDEV of OR
                NewYorkOR_line_lo10   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 1.0 STDEV of OR
                NewYorkOR_line_lo15   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.5 STDEV of OR
                NewYorkOR_line_lo175  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 1.75 STDEV of OR
                NewYorkOR_line_lo20   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 2.0 STDEV of OR
                NewYorkOR_line_lo225  := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.25 STDEV of OR
                NewYorkOR_line_lo25   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.gray)         // Opening Range Low 2.5 STDEV of OR
                NewYorkOR_line_lo30   := line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=color.red)          // Opening Range Low 3.0 STDEV of OR
                NewYorkORLabelHigh05  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                NewYorkORLabelHigh10  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                NewYorkORLabelHigh20  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                NewYorkORLabelHigh30  := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                NewYorkORLabelLow05   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                NewYorkORLabelLow10   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                NewYorkORLabelLow20   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
                NewYorkORLabelLow30   := label.new(x=na, y=na, xloc=xloc.bar_time, color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
else if NewYorkSession
    // We are in allowed New York Session hours; track hi/lo.
    NewYork_hi := math.max(srcHi, NewYork_hi)
    NewYork_lo := math.min(srcLo, NewYork_lo)
    if (NewYork_hi > NewYork_hi[1])
        NewYork_75 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.75
        NewYork_50 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.5
        NewYork_25 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.25
        if showNewYorkDrawings
            line.set_xy1(id=NewYork_line_hi, x=time, y=NewYork_hi)
            line.set_xy2(id=NewYork_line_hi, x=CashSessionEndTime, y=NewYork_hi)
            line.set_xy1(id=NewYork_line_75, x=NewYorkSessionStart, y=NewYork_75)
            line.set_xy2(id=NewYork_line_75, x=CashSessionEndTime, y=NewYork_75)
            line.set_xy1(id=NewYork_line_50, x=NewYorkSessionStart, y=NewYork_50)
            line.set_xy2(id=NewYork_line_50, x=CashSessionEndTime, y=NewYork_50)
            line.set_xy1(id=NewYork_line_25, x=NewYorkSessionStart, y=NewYork_25)
            line.set_xy2(id=NewYork_line_25, x=CashSessionEndTime, y=NewYork_25)
            if showLabels
                label.set_xy(id=NewYorkHighLabel, x=CashSessionEndTime, y=NewYork_hi)
                label.set_xy(id=NewYork75Label, x=CashSessionEndTime, y=NewYork_75)
                label.set_xy(id=NewYork50Label, x=CashSessionEndTime, y=NewYork_50)
                label.set_xy(id=NewYork25Label, x=CashSessionEndTime, y=NewYork_25)
                label.set_xy(id=NewYorkLowLabel,x=CashSessionEndTime, y=NewYork_lo)
    if (NewYork_lo < NewYork_lo[1])
        NewYork_75 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.75
        NewYork_50 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.5
        NewYork_25 := NewYork_lo+(NewYork_hi-NewYork_lo)*0.25
        if showNewYorkDrawings
            line.set_xy1(id=NewYork_line_lo, x=time, y=NewYork_lo)
            line.set_xy2(id=NewYork_line_lo, x=CashSessionEndTime, y=NewYork_lo)
            line.set_xy1(id=NewYork_line_75, x=NewYorkSessionStart, y=NewYork_75)
            line.set_xy2(id=NewYork_line_75, x=CashSessionEndTime, y=NewYork_75)
            line.set_xy1(id=NewYork_line_50, x=NewYorkSessionStart, y=NewYork_50)
            line.set_xy2(id=NewYork_line_50, x=CashSessionEndTime, y=NewYork_50)
            line.set_xy1(id=NewYork_line_25, x=NewYorkSessionStart, y=NewYork_25)
            line.set_xy2(id=NewYork_line_25, x=CashSessionEndTime, y=NewYork_25)
            if showLabels
                label.set_xy(id=NewYorkHighLabel, x=CashSessionEndTime, y=NewYork_hi)
                label.set_xy(id=NewYork75Label, x=CashSessionEndTime, y=NewYork_75)
                label.set_xy(id=NewYork50Label, x=CashSessionEndTime, y=NewYork_50)
                label.set_xy(id=NewYork25Label, x=CashSessionEndTime, y=NewYork_25)
                label.set_xy(id=NewYorkLowLabel, x=CashSessionEndTime, y=NewYork_lo)
    if showNewYorkOR and time >= NewYorkORStart and time <= NewYorkOREnd // If the Opening Range is active
        if time == NewYorkORStart
            // Reset the Hr1 price tracking vars
            NewYorkHr1hi  := srcHi
            NewYorkHr1lo  := srcLo
        // Calculate and Store the OR High and 50% - Needed for Alerts and Box drawing
        NewYorkHr1hi := math.max(srcHi, NewYorkHr1hi)
        NewYorkHr1lo := math.min(srcLo, NewYorkHr1lo)
        NewYorkHr1mid := NewYorkHr1lo+(NewYorkHr1hi-NewYorkHr1lo)*0.5
        if (NewYorkHr1hi > NewYorkHr1hi[1])
            // Plot the 1st Hour Box
            box.set_lefttop(id=NewYorkORBox, left=NewYorkORStart, top=NewYorkHr1hi) 
            box.set_rightbottom(id=NewYorkORBox, right=NewYorkOREnd, bottom=NewYorkHr1lo)
            // Plot the 1st Hour hi/low Levels
            line.set_xy1(id=NewYorkOR_line_hi, x=NewYorkORStart, y=NewYorkHr1hi)
            line.set_xy2(id=NewYorkOR_line_hi, x=CashSessionEndTime, y=NewYorkHr1hi)
            line.set_xy1(id=NewYorkOR_line_mid, x=NewYorkORStart+(time-NewYorkORStart), y=NewYorkHr1mid)
            line.set_xy2(id=NewYorkOR_line_mid, x=CashSessionEndTime, y=NewYorkHr1mid)
            line.set_xy1(id=NewYorkOR_line_lo, x=NewYorkORStart, y=NewYorkHr1lo)
            line.set_xy2(id=NewYorkOR_line_lo, x=CashSessionEndTime,  y=NewYorkHr1lo)
            if showLabels
                label.set_text(id=NewYorkORLabelHigh, text="OR High")
                label.set_xy(id=NewYorkORLabelHigh, x=CashSessionEndTime, y=NewYorkHr1hi)
                label.set_text(id=NewYorkORLabelMid, text="OR 50%")
                label.set_xy(id=NewYorkORLabelMid, x=CashSessionEndTime, y=NewYorkHr1mid)
                label.set_text(id=NewYorkORLabelLow, text="OR Low")
                label.set_xy(id=NewYorkORLabelLow, x=CashSessionEndTime, y=NewYorkHr1lo)
        if (NewYorkHr1lo < NewYorkHr1lo[1])
            // Plot the 1st Hour Box
            box.set_lefttop(id=NewYorkORBox, left=NewYorkORStart, top=NewYorkHr1hi) 
            box.set_rightbottom(id=NewYorkORBox, right=NewYorkOREnd, bottom=NewYorkHr1lo)
            // Plot the 1st Hour hi/low Levels
            line.set_xy1(id=NewYorkOR_line_hi, x=NewYorkORStart, y=NewYorkHr1hi)
            line.set_xy2(id=NewYorkOR_line_hi, x=CashSessionEndTime, y=NewYorkHr1hi)
            line.set_xy1(id=NewYorkOR_line_mid, x=NewYorkORStart+(time-NewYorkORStart), y=NewYorkHr1mid)
            line.set_xy2(id=NewYorkOR_line_mid, x=CashSessionEndTime, y=NewYorkHr1mid)
            line.set_xy1(id=NewYorkOR_line_lo, x=NewYorkORStart, y=NewYorkHr1lo)
            line.set_xy2(id=NewYorkOR_line_lo, x=CashSessionEndTime,  y=NewYorkHr1lo)
            if showLabels
                label.set_text(id=NewYorkORLabelHigh, text="OR High")
                label.set_xy(id=NewYorkORLabelHigh, x=CashSessionEndTime, y=NewYorkHr1hi)
                label.set_text(id=NewYorkORLabelMid, text="OR 50%")
                label.set_xy(id=NewYorkORLabelMid, x=CashSessionEndTime, y=NewYorkHr1mid)
                label.set_text(id=NewYorkORLabelLow, text="OR Low")
                label.set_xy(id=NewYorkORLabelLow, x=CashSessionEndTime, y=NewYorkHr1lo)
    if showNewYorkOR and time == NewYorkOREnd and showNewYorkORStdev // (At the exact end of NewYork OR, calculate and draw the STDev levels )
        // Plot the Positive IB STDEVs
        line.set_xy1(id=NewYorkOR_line_hi05, x=NewYorkOREnd+1000000, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*0.5)
        line.set_xy2(id=NewYorkOR_line_hi05, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*0.5)
        line.set_xy1(id=NewYorkOR_line_hi10, x=NewYorkOREnd+1800000, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo))
        line.set_xy2(id=NewYorkOR_line_hi10, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo))
        line.set_xy1(id=NewYorkOR_line_hi15, x=NewYorkOREnd+3600000, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*1.5)
        line.set_xy2(id=NewYorkOR_line_hi15, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*1.5)
        line.set_xy1(id=NewYorkOR_line_hi175, x=NewYorkOREnd+5000000, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*1.75)
        line.set_xy2(id=NewYorkOR_line_hi175, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*1.75)
        line.set_xy1(id=NewYorkOR_line_hi20, x=NewYorkOREnd+7200000, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*2)
        line.set_xy2(id=NewYorkOR_line_hi20, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*2)
        line.set_xy1(id=NewYorkOR_line_hi225, x=NewYorkOREnd+8800000, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*2.25)
        line.set_xy2(id=NewYorkOR_line_hi225, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*2.25)
        line.set_xy1(id=NewYorkOR_line_hi25, x=NewYorkOREnd+10800000, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*2.5)
        line.set_xy2(id=NewYorkOR_line_hi25, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*2.5)
        line.set_xy1(id=NewYorkOR_line_hi30, x=NewYorkOREnd+12800000, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*3)
        line.set_xy2(id=NewYorkOR_line_hi30, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*3)
        // Plot the Negative IB STDEVs
        line.set_xy1(id=NewYorkOR_line_lo05, x=NewYorkOREnd+1000000, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*0.5)
        line.set_xy2(id=NewYorkOR_line_lo05, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*0.5)
        line.set_xy1(id=NewYorkOR_line_lo10, x=NewYorkOREnd+1800000, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo))
        line.set_xy2(id=NewYorkOR_line_lo10, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo))
        line.set_xy1(id=NewYorkOR_line_lo15, x=NewYorkOREnd+3600000, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*1.5)
        line.set_xy2(id=NewYorkOR_line_lo15, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*1.5)
        line.set_xy1(id=NewYorkOR_line_lo175, x=NewYorkOREnd+5000000, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*1.75)
        line.set_xy2(id=NewYorkOR_line_lo175, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*1.75)
        line.set_xy1(id=NewYorkOR_line_lo20, x=NewYorkOREnd+7200000, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*2)
        line.set_xy2(id=NewYorkOR_line_lo20, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*2)
        line.set_xy1(id=NewYorkOR_line_lo225, x=NewYorkOREnd+8800000, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*2.25)
        line.set_xy2(id=NewYorkOR_line_lo225, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*2.25)
        line.set_xy1(id=NewYorkOR_line_lo25, x=NewYorkOREnd+10800000, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*2.5)
        line.set_xy2(id=NewYorkOR_line_lo25, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*2.5)
        line.set_xy1(id=NewYorkOR_line_lo30, x=NewYorkOREnd+12800000, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*3)
        line.set_xy2(id=NewYorkOR_line_lo30, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*3)
        // Plot the IB STDEV Labels
        if showLabels
            label.set_text(id=NewYorkORLabelHigh05, text="0.5 OR")
            label.set_xy(id=NewYorkORLabelHigh05, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)/2)
            label.set_text(id=NewYorkORLabelHigh10, text="1.0 OR")
            label.set_xy(id=NewYorkORLabelHigh10, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo))
            label.set_text(id=NewYorkORLabelHigh20, text="2.0 OR")
            label.set_xy(id=NewYorkORLabelHigh20, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*2)
            label.set_text(id=NewYorkORLabelHigh30, text="3.0 OR")
            label.set_xy(id=NewYorkORLabelHigh30, x=CashSessionEndTime, y=NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)*3)
            label.set_text(id=NewYorkORLabelLow05, text="-0.5 OR")
            label.set_xy(id=NewYorkORLabelLow05, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)/2)
            label.set_text(id=NewYorkORLabelLow10, text="-1.0 OR")
            label.set_xy(id=NewYorkORLabelLow10, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo))
            label.set_text(id=NewYorkORLabelLow20, text="-2.0 OR")
            label.set_xy(id=NewYorkORLabelLow20, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*2)
            label.set_text(id=NewYorkORLabelLow30, text="-3.0 OR")
            label.set_xy(id=NewYorkORLabelLow30, x=CashSessionEndTime, y=NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)*3)
// END NewYork Session Code
// ***



// New York Initial Balance Logic
// Determine the opening Bar - depending of Resolution
open_bar = switch timeframe.period
    "1" =>      time_close(timeframe.period, "0829-0830", i_timezone)
    "3" =>      time_close(timeframe.period, "0827-0830", i_timezone)
    "5" =>      time_close(timeframe.period, "0825-0830", i_timezone)
    "15" =>     time_close(timeframe.period, "0815-0830", i_timezone)
    "30" =>     time_close(timeframe.period, "0800-0830", i_timezone)
// End Opening bar code
// ******
// End of session code
// -------------------------------------------------------------------------------


// Previous Day's Open
if showPDO and timeframe.isintraday // Plot the Previous Day's Open line and label
    _CashSessionEndTime  = timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
    var PDOpen_line    = line.new(x1=_CashSessionEndTime[1], y1=PreviousDayOpen, x2=_CashSessionEndTime, xloc=xloc.bar_time, y2=PreviousDayOpen, color=i_PDOcol)    // Create the price line of the Previous Days Open
    var PDOLabel = label.new(x=na, y=na, xloc=xloc.bar_time, text="PDO", color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)            // Create the label for the Previous Days Open line
    line.set_xy1(id=PDOpen_line, x=_CashSessionEndTime-86400000, y=PreviousDayOpen)        // Draw the PDO Line from the Previous Day's open to the end of the current session
    line.set_xy2(id=PDOpen_line, x=_CashSessionEndTime, y=PreviousDayOpen)                 // Draw the PDO Line from the Previous Day's open to the end of the current session
    if showHTFLabels
        label.set_xy(id=PDOLabel, x=_CashSessionEndTime, y=PreviousDayOpen)                    // PDO Label placement
        label.set_tooltip(PDOLabel, "Previous Day Open: " + str.tostring(PreviousDayOpen))    // PDO Label tooltip with PD Open value
// END Previous Day's Open

// Previous Day's Close
if showPDC and timeframe.isintraday // Plot the Previous Day's Close line and label
    _CashSessionEndTime  = timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
    var PDClose_line    = line.new(x1=_CashSessionEndTime[1], y1=PreviousDayClose, x2=_CashSessionEndTime, xloc=xloc.bar_time, y2=PreviousDayClose, color=i_PDCcol) // Create the price line of the Previous Days Close
    var PDCLabel = label.new(x=na, y=na, xloc=xloc.bar_time, text="PDC", color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
    line.set_xy1(id=PDClose_line, x=_CashSessionEndTime-86400000, y=PreviousDayClose)        // Draw the PDC Line from the Previous Day's close to the end of the current session
    line.set_xy2(id=PDClose_line, x=_CashSessionEndTime, y=PreviousDayClose)                 // Draw the PDC Line from the Previous Day's close to the end of the current session
    if showHTFLabels
        label.set_xy(id=PDCLabel, x=_CashSessionEndTime, y=PreviousDayClose)                     // PDC Label placement
        label.set_tooltip(PDCLabel, "Previous Day Close: " + str.tostring(PreviousDayClose))    // PDC Label tooltip with PDC value
// END Previous Day's Close

// Previous Week's Open
if showPWO and timeframe.isintraday // Plot the Previous Week's Open line and label
    _CashSessionEndTime  = timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
    var PWOpen_line    = line.new(x1=_CashSessionEndTime[1], y1=PreviousWeekOpen, x2=_CashSessionEndTime, xloc=xloc.bar_time, y2=PreviousWeekOpen, color=i_PWOcol)  // Create the price line of the Previous Week Open
    var PWOLabel = label.new(x=na, y=na, xloc=xloc.bar_time, text="PWO", color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)               // Create the label for the Previous Week Open line
    line.set_xy1(id=PWOpen_line, x=_CashSessionEndTime-86400000, y=PreviousWeekOpen)        // Draw the PWO Line from the Previous Week's open to the end of the current session
    line.set_xy2(id=PWOpen_line, x=_CashSessionEndTime, y=PreviousWeekOpen)                 // Draw the PWO Line from the Previous Week's open to the end of the current session
    if showHTFLabels
        label.set_xy(id=PWOLabel, x=_CashSessionEndTime, y=PreviousWeekOpen)                   // PWO Label placement
        label.set_tooltip(PWOLabel, "Previous Week Open: " + str.tostring(PreviousWeekOpen))  // PWO Label tooltip with CW Open value
// END Current Week's Open

// Previous Week's Close
if showPWC and timeframe.isintraday // Plot the Previous Week's Close line and label
    _CashSessionEndTime  = timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00)   // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
    var PWClose_line    = line.new(x1=_CashSessionEndTime[1], y1=PreviousWeekClose, x2=_CashSessionEndTime, xloc=xloc.bar_time, y2=PreviousWeekClose, color=i_PWCcol) // Create the price line of the Previous Weeks Close
    var PWCLabel = label.new(x=na, y=na, xloc=xloc.bar_time, text="PWC", color=color.new(color.gray, 90), textcolor=color.white, style=label.style_label_left, size=size.small)
    line.set_xy1(id=PWClose_line, x=_CashSessionEndTime-86400000, y=PreviousWeekClose)        // Draw the PWC Line from the Previous Week's close to the end of the current session
    line.set_xy2(id=PWClose_line, x=_CashSessionEndTime, y=PreviousWeekClose)                 // Draw the PWC Line from the Previous Week's close to the end of the current session
    if showHTFLabels
        label.set_xy(id=PWCLabel, x=_CashSessionEndTime, y=PreviousWeekClose)                     // PWC Label placement
        label.set_tooltip(PWCLabel, "Previous Week Close: " + str.tostring(PreviousWeekClose))   // PWC Label tooltip with PWC value
// END Previous Week's Close


// ALERTS!
// Check if price crosses key levels and generate alerts
f_triggerGlobexLow()         // Price crosses the Globex Overnight Low level?
f_triggerGlobexHigh()        // Price crosses the Globex Overnight High level?
f_triggerNewYorkOR50perc()   // When the New York Opening Range has ended... check to see if the 50% level is crossed
f_triggerNewYorkSTDEVpos05() // When the New York Opening Range has ended... check to see if the STDEV 0.5 level is crossed
f_triggerNewYorkSTDEVpos10() // When the New York Opening Range has ended... check to see if the STDEV 1.0 level is crossed
f_triggerNewYorkSTDEVneg05() // When the New York Opening Range has ended... check to see if the STDEV -0.5 level is crossed
f_triggerNewYorkSTDEVneg10() // When the New York Opening Range has ended... check to see if the STDEV -1.0 level is crossed
// End of Alert section

// Start Plotting
bgcolor(showGlobex == true and time == GlobexSession ? color.new(i_GlobexSessionCol,90) : na)   // Highlight the Globex (Overnight) Range
bgcolor(showOpenbar == true and open_bar ? color.new(i_NYSessionCol, 75) : na)                  // Highlight the Bar before the New York Cash Open
bgcolor(showAsian == true and time == AsianSession ? color.new(i_AsianSessionCol,90) : na)      // Highlight the Asian Range
bgcolor(showLondon == true and time == LondonSession ? color.new(i_LondonSessionCol,90) : na)   // Highlight the London Range
bgcolor(showNewYork == true and time == NewYorkSession ? color.new(i_NYSessionCol,90) : na)     // Highlight the NewYork Range


// Debug plots
plot(showDebug ? NewYorkHr1lo : na, title='NewYorkHr1lo', color=color.new(#00ffaa, 70))
plot(showDebug ? NewYorkHr1mid : na, title='NewYorkHr1mid', color=color.new(#00ffaa, 70))
plot(showDebug ? NewYorkHr1hi : na, title='NewYorkHr1hi', color=color.new(#00ffaa, 70))
plot(showDebug ? NewYork_hi : na, title='NewYork_hi', color=color.new(#00ffaa, 70))
plot(showDebug ? NewYork_lo : na, title='NewYork_lo', color=color.new(#00ffaa, 70))
plot(showDebug ? (NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo)/2) : na, title='NewYorkSTDEVpos05', color=color.new(#00ffaa, 70))
plot(showDebug ? NewYorkHr1hi+(NewYorkHr1hi-NewYorkHr1lo) : na, title='NewYorkSTDEVpos10', color=color.new(#00ffaa, 70))
plot(showDebug ? (NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo)/2) : na, title='NewYorkSTDEVneg05', color=color.new(#00ffaa, 70))
plot(showDebug ? NewYorkHr1lo-(NewYorkHr1hi-NewYorkHr1lo) : na, title='NewYorkSTDEVneg10', color=color.new(#00ffaa, 70))