iBox, Initial Balance | IB High, Low, Midpoint | Opening
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Roul_Charts
// Roul
// 11.2022
// 12.2022 seems that my changes where not saved. So had to reupload it...
// 03.2023 Reworked Settings menu, Reworked Style menu, added closing, added Crypto Exchanges and pairs with UTC+0 as IB range
// 11.2023 Added more Ticker and Exchanges, Added SouthAfrica, Added Premarket Range for US and EU, Added more IB Extensions, 
//         Added Yesterday High and Low Lines
//         prepared a new GAP Detector Indicator based on iBOX Logic
//         Added crossover and crossunder Alertconditions for all Lines
//         Added the Plot x Days back Feature, FINALLY!!
//@version=5


indicator(title='iBox, Initial Balance | IB High, Low, Mid | Open, Close', shorttitle='iBOX', overlay=true, max_bars_back=1050, max_boxes_count=250, max_labels_count=250, max_lines_count=250)

//####################################
// Settings
//####################################
GP1 = "===== Settings ====="

Plot_x_days           = input.int(defval=10, title='Plot only last x days', tooltip='please add days for weekends too', group=GP1)


//####################################
// Timezones and IB Ranges
//####################################
GP2a = "=============== Universal ==============="
Timezone                    = input.string(defval="Europe/Berlin", title="Universal Timezone", group=GP2a, 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 Universal Exchange Timezone")
Select_Universal_IB         = input.session(title="Universal IB Time",   defval="0900-0959", group=GP2a, inline="Universal IB")

GP2b = "=============== Europe ==============="
Timezone_EU                 = input.string(defval="Europe/Berlin", title="Europe Timezone", group=GP2b, 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 European Exchange Timezone")
Select_EU_IB                = input.session(title="EU IB Time",          defval="0900-0959", group=GP2b, inline="EU IB")
Select_EU_Premarket         = input.session(title="EU Premarket Time",   defval="0800-0859", group=GP2b, inline="EU Premarket")
// Select_EU_Session           = input.session(title="EU", defval="0900-1730", group=GP2b, inline="EU")                      // EU Session, Monday - Friday


GP2c = "=============== USA ==============="
Timezone_US                 = input.string(defval="America/New_York", title="USA Timezone", group=GP2c, 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 USA Exchange Timezone")
Select_US_IB                = input.session(title="US IB Time",          defval="0930-1029", group=GP2c, inline="US IB")
Select_US_Premarket         = input.session(title="US Premarket Time",   defval="0830-0929", group=GP2c, inline="US Premarket")
// Select_US_Session           = input.session(title="US", defval="0930-1600", group=GP2c, inline="US")                      // US Session, Monday - Friday


GP2d = "=============== Brazil ==============="
Timezone_Brazil             = input.string(defval="America/Sao_Paulo", title="Brazil Timezone", group=GP2d, 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 Brazilian Exchange Timezone")
Select_Brazil_IB            = input.session(title="Brazil IB Time",      defval="1000-1059", group=GP2d, inline="Brazil IB")

GP2e = "=============== Asia ==============="
Timezone_Asia               = input.string(defval="Asia/Shanghai", title="Asia Timezone", group=GP2e, 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 Asian Exchange Timezone")
Select_Asia_IB              = input.session(title="Asia IB Time",        defval="0915-1014", group=GP2e, inline="Asia IB")
Select_Asia_Session         = input.session(title="Asia Session", defval="0800-1459", group=GP2e, inline="AS")               // Asian Session, During Winter Time
//Select_Asia_Session         = input.session(title="Asia Session", defval="0800-1359", group=GP2e, inline="AS")             // Asian Session, During Summer Time


GP2f = "=============== Tokyo ==============="
Timezone_Tokyo              = input.string(defval="Asia/Tokyo", title="Tokyo Timezone", group=GP2f, 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 Tokyo Exchange Timezone")
Select_Tokyo_IB             = input.session(title="Tokyo IB Time",       defval="0900-0959", group=GP2f, inline="Tokyo IB")

GP2g = "=============== India ==============="
Timezone_India              = input.string(defval="Asia/Kolkata", title="India Timezone", group=GP2g, 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 Indian Exchange Timezone")
Select_India_IB             = input.session(title="India IB Time",       defval="0900-0959", group=GP2g, inline="India IB")

GP2h = "=============== Ozeania ==============="
Timezone_Oceania            = input.string(defval="Australia/Sydney", title="Oceania Timezone", group=GP2h, 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 Oceanian Exchange Timezone")
Select_Oceania_IB           = input.session(title="Oceania IB Time",     defval="1000-1059", group=GP2h, inline="Oceania IB")

GP2i = "=============== SouthAfrica ==============="
Timezone_SouthAfrica        = input.string(defval="Africa/Johannesburg"	, title="SouthAfrica Timezone", group=GP2i, options=["GMT", "Africa/Johannesburg", "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 SouthAfrica Exchange Timezone")
Select_SouthAfrica_IB       = input.session(title="SouthAfrica IB Time",     defval="0900-0959", group=GP2i, inline="SouthAfrica IB")

GP2j = "=============== Crypto ==============="
Timezone_Crypto            = input.string(defval="Etc/UTC", title="Crypto Timezone", group=GP2j, 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 Crypto Exchange Timezone")
Select_Crypto_IB           = input.session(title="Crypto IB Time",     defval="0000-0059", group=GP2j, inline="Crypto IB")



//####################################
// Initial Balance Settings
//####################################
GP6 = "===== Initial Balance Settings ====="
Lines_IB_active                 = input(title='Show IB Lines?', defval=true, group=GP6)
IB_Lines_width                  = input.int(2, 'IB Lines Width', minval=1, maxval=4, group=GP6)
IB_Lines_Color                  = input(color.new(color.rgb(166, 51, 91), 0), 'IB Lines Color', group=GP6)
IB_Lines_Style_Option           = input.string("solid (─)", title="IB Lines Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP6)
IB_Lines_Extension_alt          = input(title='Use alternate possibly wrong IB Extension calculation?', defval=false, tooltip="Normal Calculation is: IB Range = IB High - IB Low that is the Range of the Initial Balance. This seems to be valid and heavily recogniced from the market. The alternate Calculation is the distance from Opening to IB High and the distance from Opening to IB Low which can work but is not my favorite", group=GP6)


GP7 = "===== Initial Balance 1.5 Extension Settings ====="
Lines_IB_15_Extension_active    = input(title='Show IB 1.5 Extension Lines?', defval=false, group=GP7)
IB_Lines15_width                = input.int(3, 'IB 1.5 Lines Width', minval=1, maxval=4, group=GP7)
IB_Lines15_Color                = input(color.new(color.rgb(127,39,70), 0), 'IB 1.5 Lines Color', group=GP7)
IB_Lines15_Style_Option         = input.string("solid (─)", title="IB 1.5 Lines Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP7)

GP8 = "===== Initial Balance 2.0 Extension Settings ====="
Lines_IB_20_Extension_active    = input(title='Show IB 2.0 Extension Lines?', defval=false, group=GP8)
IB_Lines20_width                = input.int(4, 'IB 2.0 Lines Width', minval=1, maxval=4, group=GP8)
IB_Lines20_Color                = input(color.new(color.rgb(107,33,59), 0), 'IB 2.0 Lines Color', group=GP8)
IB_Lines20_Style_Option         = input.string("solid (─)", title="IB 2.0 Lines Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP8)

GP8a = "===== Initial Balance 2.5 Extension Settings ====="
Lines_IB_25_Extension_active    = input(title='Show IB 2.5 Extension Lines?', defval=false, group=GP8a)
IB_Lines25_width                = input.int(4, 'IB 2.5 Lines Width', minval=1, maxval=4, group=GP8a)
IB_Lines25_Color                = input(color.new(color.rgb(107,33,59), 0), 'IB 2.5 Lines Color', group=GP8a)
IB_Lines25_Style_Option         = input.string("solid (─)", title="IB 2.5 Lines Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP8a)

GP8b = "===== Initial Balance 3.0 Extension Settings ====="
Lines_IB_30_Extension_active    = input(title='Show IB 3.0 Extension Lines?', defval=false, group=GP8b)
IB_Lines30_width                = input.int(4, 'IB 3.0 Lines Width', minval=1, maxval=4, group=GP8b)
IB_Lines30_Color                = input(color.new(color.rgb(107,33,59), 0), 'IB 3.0 Lines Color', group=GP8b)
IB_Lines30_Style_Option         = input.string("solid (─)", title="IB 3.0 Lines Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP8b)


GP9 = "===== Initial Balance Halfback Settings ====="
Lines_IB_Halfback_active        = input(title='Show IB Halfback Line?', defval=true, group=GP9)
IB_Halfback_Line_width          = input.int(2, 'IB Halfback Line Width', minval=1, maxval=4, group=GP9)
IB_Halfback_Line_Color          = input(color.new(color.rgb(166, 51, 91), 0), 'IB Halfback Line Color', group=GP9)
IB_Halfback_Line_Style_Option   = input.string("dotted (┈)", title="IB Halfback Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP9)


GP9a = "===== Premarket Line Settings ====="
Lines_Premarket_active        = input(title='Show Premarket Line?', defval=false, group=GP9a)
Premarket_Line_width          = input.int(1, 'Premarket Line Width', minval=1, maxval=4, group=GP9a)
Premarket_High_Line_Color     = input(color.new(#51b0fe, 0), 'Premarket High Line Color', group=GP9a)
Premarket_Low_Line_Color      = input(color.new(#51b0fe, 0), 'Premarket Low Line Color', group=GP9a)

Premarket_High_Line_Style_Option  = input.string("arrow right (→)", title="Premarket High Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP9a)
Premarket_Low_Line_Style_Option   = input.string("arrow right (→)", title="Premarket Low Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP9a)


GP10 = "===== Opening Line Settings ====="
Lines_Opening_active            = input(title='Show Opening Line?', defval=true, group=GP10)
Opening_Line_width              = input.int(2, 'IB Opening Line Width', minval=1, maxval=4, group=GP10)
Opening_Line_Color              = input(color.new(color.rgb(218, 135 , 24), 0), 'Opening Line Color', group=GP10)
Opening_Line_Style_Option       = input.string("dotted (┈)", title="Opening Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP10)


GP11 = "===== Previous Day Closing Line Settings ====="
PrevD_Lines_Closing_active      = input(title='Show Yesterdays Closing?', defval=false, group=GP11)
PrevD_Closing_Line_width        = input.int(2, 'Yesterday Closing Line Width', minval=1, maxval=4, group=GP11)
PrevD_Closing_Line_Color        = input(color.new(#653ac9, 0), 'Yesterday Closing Line Color', group=GP11)
PrevD_Closing_Line_Style_Option = input.string("dashed (╌)", title="Yesterday Closing Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP11)

GP11a = "===== Previous Day High Line Settings ====="
PrevD_Lines_High_active         = input(title='Show Yesterdays High?', defval=false, group=GP11a)
PrevD_High_Line_width           = input.int(2, 'Yesterday High Line Width', minval=1, maxval=4, group=GP11a)
PrevD_High_Line_Color           = input(color.new(#028ea3, 0), 'Yesterday High Line Color', group=GP11a)
PrevD_High_Line_Style_Option    = input.string("dashed (╌)", title="Yesterday High Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP11a)

GP11b = "===== Previous Day Low Line Settings ====="
PrevD_Lines_Low_active         = input(title='Show Yesterdays Low?', defval=false, group=GP11b)
PrevD_Low_Line_width           = input.int(2, 'Yesterday Low Line Width', minval=1, maxval=4, group=GP11b)
PrevD_Low_Line_Color           = input(color.new(#04437e, 0), 'Yesterday Low Line Color', group=GP11b)
PrevD_Low_Line_Style_Option    = input.string("dashed (╌)", title="Yesterday Low Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP11b)


GP12 = "===== Asia Line Settings ====="
Lines_Asia_Session_active       = input(title='Show Asia Range High/Low?', defval=false, group=GP12)
Asia_Line_width                 = input.int(2, 'Asia Line Width', minval=1, maxval=4, group=GP12)
Asia_Session_High_Line_Color    = input(color.new(color.rgb(138,138,138), 0), 'Asia Session High Line Color', group=GP12)
Asia_Session_Low_Line_Color     = input(color.new(color.rgb(138,138,138), 0), 'Asia Session Low Line Color', group=GP12)

Asia_Session_High_Line_Style_Option    = input.string("solid (─)", title="Asia Session High Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP12)
Asia_Session_Low_Line_Style_Option     = input.string("solid (─)", title="Asia Session Low Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)", "arrow left (←)", "arrow right (→)", "arrows both (↔)"], group=GP12)


GP13 = "===== Label Settings ====="
Labels_active                   = input(title='Show Text Labels for Lines?', defval=false, group=GP13)
Labels_Transparency             = input.int(30, 'Labels Transparency?', minval=0, maxval=100, group=GP13)

//####################################
// Checks
//####################################

//Current Candle in IB Range?
In_Universal_IB                = not na(time(timeframe.period, Select_Universal_IB, Timezone))                         // Calculate time for the Universal IB
In_EU_IB                       = not na(time(timeframe.period, Select_EU_IB, Timezone_EU))                             // Calculate time for the EU IB
In_US_IB                       = not na(time(timeframe.period, Select_US_IB, Timezone_US))                             // Calculate time for the US IB
In_Brazil_IB                   = not na(time(timeframe.period, Select_Brazil_IB, Timezone_Brazil))                     // Calculate time for the Brazil IB
In_Asia_IB                     = not na(time(timeframe.period, Select_Asia_IB, Timezone_Asia))                         // Calculate time for the Asia IB
In_Tokyo_IB                    = not na(time(timeframe.period, Select_Tokyo_IB, Timezone_Tokyo))                       // Calculate time for the Tokyo IB
In_India_IB                    = not na(time(timeframe.period, Select_India_IB, Timezone_India))                       // Calculate time for the India IB
In_Oceania_IB                  = not na(time(timeframe.period, Select_Oceania_IB, Timezone_Oceania))                   // Calculate time for the Oceania IB
In_SouthAfrica_IB              = not na(time(timeframe.period, Select_SouthAfrica_IB, Timezone_SouthAfrica))           // Calculate time for the SouthAfrica IB
In_Crypto_IB                   = not na(time(timeframe.period, Select_Crypto_IB, Timezone_Crypto))                     // Calculate time for the Crypto IB


//Current Candle in Session?
// In_Globex_Session              = not na(time(timeframe.period, Select_Globex_Session, Timezone))                    // Calculate time for the Globex/Overnight session
In_Asia_Session                = not na(time(timeframe.period, Select_Asia_Session, Timezone_Asia))                    // Calculate time for the Asian Session
In_EU_Premarket                = not na(time(timeframe.period, Select_EU_Premarket, Timezone_EU))                      // Calculate time for the Asian Session
In_US_Premarket                = not na(time(timeframe.period, Select_US_Premarket, Timezone_US))                      // Calculate time for the Asian Session


// In_EU_Session                  = not na(time(timeframe.period, Select_EU_Session, Timezone_EU))                     // Calculate time for the EU Session
// In_US_Session                  = not na(time(timeframe.period, Select_US_Session, Timezone_US))                     // Calculate time for the US Session
//In_Day_Session                 = not na(time(timeframe.period, Select_Day_Session, Timezone_EU))                       // Calculate time for the Day Session

//In_Day_Session                 = time(timeframe.period, Select_Day_Session, Timezone_EU)                       // Calculate time for the Day Session


// Define Session End Time and End of Lines
// US_Session_EndHour          = input.int(title="US Cash Session End Hour", defval=21, minval=0, maxval=23, group=GP1, inline="US_End")                                                                                                   // US Session End Hour
// US_Session_EndMin           = input.int(title="US Cash Session End Min.", defval=59, minval=0, maxval=59, group=GP1, inline="US_End", tooltip="This is where all the lines and drawings end. Must be Less than the start of Globex")    // US Session End Minute

// var Cash_Session_EndTime    = timestamp(Timezone, year, month, dayofmonth, US_Session_EndHour, US_Session_EndMin, 00)           // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)


// NewYork_OR_offset           = input.int(title="New York Open Offset", tooltip="New York Session Opening Range Starts after x minutes", defval=30, minval=0, maxval=59, group=GP1)     // New York Opening Range Initial Balance Opening Minute


// Globex_Session_Col          = input.color(title="Session",tooltip="Globex Session Highlight Color", defval=color.silver, group=GP1, inline="GS")             // Globex (Overnight) Session, color setting for background highlights
// Asia_Session_Col            = input.color(title="Session",tooltip="Asia Session Highlight Color",   defval=color.white, group=GP1, inline="AS")              // Asia Session, color setting for background highlights, 1st hr box and High and Low lines
// EU_Session_Col              = input.color(title="Session",tooltip="EU Session Highlight Color",     defval=color.green, group=GP1, inline="LS")              // EU Session, color setting for background highlights, 1st hr box and High and Low lines
// US_Session_Col              = input.color(title="Session",tooltip="US Session Highlight Color",     defval=color.blue, group=GP1, inline="NY")               // US Session, color setting for background highlights, 1st hr box and High and Low lines


// Globex_Level_Col            = input.color(title="Levels",tooltip="Globex Levels Color",             defval=color.gray, group=GP1, inline="GS")               // Globex (Overnight) Session, color setting for level lines
// Asia_Level_Col              = input.color(title="Levels",tooltip="Asia Levels Color",               defval=color.gray, group=GP1, inline="AS")               // Asia Session, color setting for level lines
// EU_Level_Col                = input.color(title="Levels",tooltip="EU Levels Color",                 defval=color.gray, group=GP1, inline="EU")               // EU Session, color setting for level lines
// US_Level_Col                = input.color(title="Levels",tooltip="US Level Color",                  defval=color.gray, group=GP1, inline="US")               // US Session, color setting for level lines


//####################################
// Variables
//####################################

var line IB_High_Line = na
var line IB_Low_Line = na
var line IB_High15_Line = na
var line IB_High20_Line = na
var line IB_High25_Line = na
var line IB_High30_Line = na
var line IB_Low15_Line = na
var line IB_Low20_Line = na
var line IB_Low25_Line = na
var line IB_Low30_Line = na
var line IB_Halfback_Line = na
var line Premarket_High_Line = na
var line Premarket_Low_Line = na
var line Opening_Line = na
var line PrevD_Closing_Line = na
var line PrevD_High_Line = na
var line PrevD_Low_Line = na
var line Asia_Session_High_Line = na
var line Asia_Session_Low_Line = na

var IB_High_value = 0.0
var IB_High15_value = 0.0
var IB_High20_value = 0.0
var IB_High25_value = 0.0
var IB_High30_value = 0.0
var IB_Low_value = 0.0
var IB_Low15_value = 0.0
var IB_Low20_value = 0.0
var IB_Low25_value = 0.0
var IB_Low30_value = 0.0
var IB_Halfback_value = 0.0

var Premarket_Start_Time = 0
var Premarket_End_Time = 0
var Premarket_High_value = 0.0
var Premarket_Low_value = 0.0

var Opening_value = 0.0
var PrevD_Closing_value = 0.0
var PrevD_High_value = 0.0
var PrevD_Low_value = 0.0
var PrevD_Closing_time = 0
var Start_Time = 0
var End_Time = 0

var bool Relevant_IB_Range = false
var bool Relevant_Premarket = false

var Day_Session_End = 0

var Asia_Session_Start_Time = 0
var Asia_Session_End_Time = 0
var Asia_Session_High_value = 0.0
var Asia_Session_Low_value = 0.0

var label IB_Low_Label = na
var label IB_Low15_Label = na
var label IB_Low20_Label = na
var label IB_Low25_Label = na
var label IB_Low30_Label = na
var label IB_High_Label = na
var label IB_High15_Label = na
var label IB_High20_Label = na
var label IB_High25_Label = na
var label IB_High30_Label = na
var label IB_Halfback_Label = na
var label Premarket_High_Label = na
var label Premarket_Low_Label = na
var label Opening_Label = na
var label PrevD_Closing_Label = na
var label PrevD_High_Label = na
var label PrevD_Low_Label = na
var label Asia_Session_High_Label = na
var label Asia_Session_Low_Label = na


//####################################
// Define Exchanges and Ticker Symbols for Ranges
//####################################

EU_Index_Array          = array.from("EUREX","EUREX_DLY","EURONEXT","EURONEXT_DLY","ICEEUR","ICEEUR_DLY","TRADEGATE","XETR","XETR_DLY")
EU_Ticker_Array         = array.from("DAX30","DAX40","DAXEUR","GERMANY40MINICFD","DE30EUR","DE40","DEU40","GER30","GER40","GERMANY40CFD","GRXEUR","GDAXIM","3XJN","GDAXI","DECEUR","DE30.F","GER40FT","DAX","MIDDE50","MDAX","GERMID50","TDXP","GERTEC30","TECDAX","FTSE100","FTSGBP","UK100","UK100.F","UK100CFD","UK100GBP","UKXGBP","FTSE","UKCGBP","UK100FT","FR40","FR40EUR","FRA40","FRANCE40CFD","FRXEUR","FCHI","CAC","CACEUR","FRA40FT","ESX50","ESXEUR","EU50","EU50EUR","EUSTX50","EURO50","EUCEUR","IT40","ITA40","ITALY40CFD","MIBEUR","SUI20","SW20","SWI20","SWICHF","CH20","SMI","SWCCHF",
 "CH20CHF","ES35","ESP35","SP35","SPA35","SPAIN35CFD","ESCEUR","ESPIXEUR","NETH25","NL25","NL25EUR","NTH25","NED25","OMX30","OMXS30","NOR25","OBX20","OBX25")

US_Index_Array          = array.from("CME_MINI","CME_MINI_DL","DJ","DJ_DLY","NASDAQ","NASDAQ_DLY","SP","SP_DLY","TSX","TSX_DLY","CSE","NYSE")
US_Ticker_Array         = array.from("NAS100","NAS100USD","NASDAQ","NDQ100","NDQM","NDQUSD","NDX","NQ1!","NSXUSD","US100","USTEC","USTEC.F","USTECH100CFD","USATEC","NQCUSD","NAS100FT","DXY","USXUSD","USDX","USDOLLAR","RTY","US2000","RUT","US2000USD","USARUS","USSMALLCAP2000CFD","SP500","SPIUSD","SPX","SPX500","SPX500USD","SPXM","SPXUSD","US500","US500.F","USSP500CFD","USA500","SPCUSD","SP500FT","DJ30","DJ30.F","DJI","DOWUSD","US30","US30USD","WALLSTREETCFD","WS30M","USAIND","DJCUSD","DJ30FT","VIX","VOLX","CA60","CAN60")

Brazil_Index_Array      = array.from("BMFBOVESPA","BMFBOVESPA_DLY")
Brazil_Ticker_Array     = array.from("BFSPX","BRA50","IBRX50","BVSPX")

Asia_Index_Array        = array.from("SSE","SSE_DLY","HSI","HSI_DLY")
Asia_Ticker_Array       = array.from("CHINA50","CHINA50CFD","CHINAH","CHN50","CN50","CN50USD","CNXUSD","CNCUSD","CHINAHHKD","CHINA50FT","HKIND","HK33HKD","HK50","HK50.F","HKXHKD","HONGKONG50CFD","HSI","HSXHKD","HKCHKD","HK50FT","SCI25","SG30SGD","SG25","SIMSCI","STI30")

Tokyo_Index_Array       = array.from("TOCOM","TOCOM_DLY","TSE","TSE_DLY")
Tokyo_Ticker_Array      = array.from("J225","JAP225","JAPAN225CFD","JP225USD","JP225YJPY","JPN225","JPXJPY","NIKKEI225","NKIUSD","NIKKEI","JP225","NKCJPY","JPN225FT")

India_Index_Array       = array.from("NSE","NSE_DLY","BSE","BSE_DLY")
India_Ticker_Array      = array.from("INDIA50","INDIA50CFD","INDUSD","NIFTY50","NIFTY","IND50")

Oceania_Index_Array     = array.from("ASX","ASX_DLY")
Oceania_Ticker_Array    = array.from("ASX200","ASXAUD","AU200","AU200AUD","AUS200","AUSTRALIA200CFD","AUXAUD","AUS","AUCAUD","SPI200")

SouthAfrica_Index_Array  = array.from("JSE", "JSE_DLY")
SouthAfrica_Ticker_Array = array.from("SA40")

Crypto_Index_Array      = array.from("BINANCE","BINANCEUS","BINGX","BITFINEX","BITFLYER","BITGET","BITHUMB","BITKUB","BITMEX","BITPANDAPRO","HONEYSWAPPOLYGON","HONEYSWAP","INTOTHEBLOCK","KORBIT","KRAKEN","KUCOIN","MEXC","OKCOIN","OKX","PANCAKESWAP","BITRUE","BITSO","BITSTAMP","BITTREX","BTSE","BYBIT","CEXIO","COINMETRICS","COINBASE","COINEX","COINFLOOR","PANGOLIN","PHEMEX","POLONIEX","PYTH","QUICKSWAP","SPOOKYSWAP","SUSHISWAP","SUSHISWAPPOLYGON","THEROCKTRADING","TIMEX","TRADERJOE","UNISWAP","UNISWAP3ARBITRUM","UNISWAP3ETH","UNISWAP3POLYGON","UPBIT","WHITEBIT","WOONETWORK","XEXCHANGE","DEFILLAMA","DELTA","DERIBIT","DYDX","EXMO","GATEIO","GEMINI","GLASSNODE")
Crypto_Ticker_Array     = array.from("0XUSD","1INCHBTC","1INCHUSD","AAVEUSD","AAVEUSDY","ADAUSD","ALICEUSD","ALOGUSD","ANTUSD","ATOMUSD","AVAXUSD","AXSUSD","BALBTC","BALUSD","BALUSDT","BANDUSD","BATUSD","BCHEUR","BCHUSD","BNBUSD","BNTUSD","BTCBYN","BTCEUR","BTCGBP","BTCUSD",
 "BTCUSDC","BTCUSDT","CHRUSD","CHZBTC","CHZUSDT","COMPUSD","COMPUSDC","COMPUSDT","CRVBTC","CRVUSD","CRVUSDT","DAIUSD","DAIUSDT","DASHUSD","DOGEUSD","DOTUSD","DYDXUSD","EGLDUSD","ENJUSDT","EOSUSD","ETCUSD","ETHBTC","ETHBYN","ETHEUR","ETHUSD",
 "ETHUSDC","FILUSD","FRMUSD","GALAUSD","GRTBTC","GRTUSD","HBARUSD","HOTUSD","ICPUSD","IOSTUSD","KNCUSD","KNCUSDT","LINKUSD","LINKUSDT","LRCUSD","LRCUSDT","LTCBTC","LTCBYN","LTCEUR","LTCUSD","LTCUSDT","MANAUSD","MATICUSD","MATICUSD C","MKRBTC",
 "MKRUSD","MKRUSDC","NEARUSD","NEOUSD","OCEANUSD","OMGUSD","ONEUSD","QTUMUSD","REPUSD","SANDUSD","SHIBUSD","SHIBUSDC","SKLUSD","SNXUSD","SNXUSDT","SOLUSD","SRMBTC","SUSHIUSD","SXPUSD","THETAUSD","TRXUSD","UMAUSD","UNIUSD","UNIUSDT","USDCUSD",
 "USDTUSD","USDUSDC","VETUSD","WBTCUSD","XLMUSD","XMRUSD","XRBTC","XRPBYN","XRPEUR","XRPUSD","XTZUSD","YFIUSD","ZECUSD")



Ticker_EU_Range          = array.includes(EU_Index_Array, syminfo.prefix)           or array.includes(EU_Ticker_Array, syminfo.ticker)
Ticker_US_Range          = array.includes(US_Index_Array, syminfo.prefix)           or array.includes(US_Ticker_Array, syminfo.ticker)
Ticker_Brazil_Range      = array.includes(Brazil_Index_Array, syminfo.prefix)       or array.includes(Brazil_Ticker_Array, syminfo.ticker)
Ticker_Asia_Range        = array.includes(Asia_Index_Array, syminfo.prefix)         or array.includes(Asia_Ticker_Array, syminfo.ticker)
Ticker_Tokyo_Range       = array.includes(Tokyo_Index_Array, syminfo.prefix)        or array.includes(Tokyo_Ticker_Array, syminfo.ticker)
Ticker_India_Range       = array.includes(India_Index_Array, syminfo.prefix)        or array.includes(India_Ticker_Array, syminfo.ticker)
Ticker_Oceania_Range     = array.includes(Oceania_Index_Array, syminfo.prefix)      or array.includes(Oceania_Ticker_Array, syminfo.ticker)
Ticker_SouthAfrica_Range = array.includes(SouthAfrica_Index_Array, syminfo.prefix)  or array.includes(SouthAfrica_Ticker_Array, syminfo.ticker)
Ticker_Crypto_Range      = array.includes(Crypto_Index_Array, syminfo.prefix)       or array.includes(Crypto_Ticker_Array, syminfo.ticker)


//####################################
// Functions
//####################################


//Function to define Sessions Lows

SessionLow(sessionTime, sessionTimeZone=syminfo.timezone) =>
    insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
    var float sessionLowPrice = na

    if insideSession and not insideSession[1]
        sessionLowPrice := low
    else if insideSession
        sessionLowPrice := math.min(sessionLowPrice, low)
    
    sessionLowPrice


//Function to define Sessions Highs

SessionHigh(sessionTime, sessionTimeZone=syminfo.timezone) =>
    insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
    var float sessionHighPrice = na

    if insideSession and not insideSession[1]
        sessionHighPrice := high
    else if insideSession
        sessionHighPrice := math.max(sessionHighPrice, high)
    
    sessionHighPrice



//Function to define Sessions Opening

SessionOpening(sessionTime, sessionTimeZone=syminfo.timezone) =>
    insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
    var float sessionOpeningPrice = na

    sessionOpeningPrice := insideSession and not insideSession[1] ? open : sessionOpeningPrice[1]


//Function to define Previous Day Values

PrevDayClosing_Value() =>
    var float PrevDayClosingPrice = na

    PrevDayClosingPrice := request.security(syminfo.tickerid, "1D", close[1], barmerge.gaps_on, lookahead=barmerge.lookahead_on)

PrevDayHigh_Value() =>
    var float PrevDayHighPrice = na

    PrevDayHighPrice := request.security(syminfo.tickerid, "1D", high[1], barmerge.gaps_on, lookahead=barmerge.lookahead_on)

PrevDayLow_Value() =>
    var float PrevDayLowPrice = na

    PrevDayLowPrice := request.security(syminfo.tickerid, "1D", low[1], barmerge.gaps_on, lookahead=barmerge.lookahead_on)


PrevDayClosing_Time() =>
    var int PrevDayClosingTime = 0
    
    PrevDayClosingTime := request.security(syminfo.tickerid, "1D", time_close[1], barmerge.gaps_on, lookahead=barmerge.lookahead_on)


PrevDayFridayClosing_Time() =>
    var int PrevDayFridayClosingTime = 0
    
    PrevDayFridayClosingTime := request.security(syminfo.tickerid, "1D", time_close[2])


//Function to define Sessions Start Time

SessionStart(sessionTime, sessionTimeZone=syminfo.timezone) =>
    insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
    var int sessionStartTime = 0
    
    sessionStartTime := insideSession and not insideSession[1] ? time : sessionStartTime[1]


Lines_Plot(_Start_Time, _Start_Value, _End_Time, _color, _style, _width) =>
    var line _line = na
    //line.delete(_line)

    _line := line.new(x1=_Start_Time, y1=_Start_Value, x2=_End_Time, y2=_Start_Value, xloc=xloc.bar_time, color=_color, style=_style, width=_width)
    _line

//####################################
// Functions end!
//####################################


// Call functions to separate here between US, EU and Asia

if Ticker_EU_Range
    IB_Low_value                := SessionLow(Select_EU_IB, Timezone_EU)
    IB_High_value               := SessionHigh(Select_EU_IB, Timezone_EU)
    Opening_value               := SessionOpening(Select_EU_IB, Timezone_EU)
    Start_Time                  := SessionStart(Select_EU_IB, Timezone_EU)
    Premarket_Start_Time        := SessionStart(Select_EU_Premarket, Timezone_EU)
    Premarket_Low_value         := SessionLow(Select_EU_Premarket, Timezone_EU)
    Premarket_High_value        := SessionHigh(Select_EU_Premarket, Timezone_EU)
    Relevant_IB_Range           := In_EU_IB
    Relevant_Premarket          := In_EU_Premarket

  
else if Ticker_US_Range
    IB_Low_value                := SessionLow(Select_US_IB, Timezone_US)
    IB_High_value               := SessionHigh(Select_US_IB, Timezone_US)
    Opening_value               := SessionOpening(Select_US_IB, Timezone_US)
    Start_Time                  := SessionStart(Select_US_IB, Timezone_US)
    Premarket_Start_Time        := SessionStart(Select_US_Premarket, Timezone_US)
    Premarket_Low_value         := SessionLow(Select_US_Premarket, Timezone_US)
    Premarket_High_value        := SessionHigh(Select_US_Premarket, Timezone_US)
    Relevant_IB_Range           := In_US_IB
    Relevant_Premarket          := In_US_Premarket


else if Ticker_Brazil_Range
    IB_Low_value                := SessionLow(Select_Brazil_IB, Timezone_Brazil)
    IB_High_value               := SessionHigh(Select_Brazil_IB, Timezone_Brazil)
    Opening_value               := SessionOpening(Select_Brazil_IB, Timezone_Brazil)
    Start_Time                  := SessionStart(Select_Brazil_IB, Timezone_Brazil)
    Relevant_IB_Range           := In_Brazil_IB


else if Ticker_Asia_Range
    IB_Low_value                := SessionLow(Select_Asia_IB, Timezone_Asia)
    IB_High_value               := SessionHigh(Select_Asia_IB, Timezone_Asia)
    Opening_value               := SessionOpening(Select_Asia_IB, Timezone_Asia)
    Start_Time                  := SessionStart(Select_Asia_IB, Timezone_Asia)
    Relevant_IB_Range           := In_Asia_IB


else if Ticker_Tokyo_Range
    IB_Low_value                := SessionLow(Select_Tokyo_IB, Timezone_Tokyo)
    IB_High_value               := SessionHigh(Select_Tokyo_IB, Timezone_Tokyo)
    Opening_value               := SessionOpening(Select_Tokyo_IB, Timezone_Tokyo)
    Start_Time                  := SessionStart(Select_Tokyo_IB, Timezone_Tokyo)
    Relevant_IB_Range           := In_Tokyo_IB


else if Ticker_India_Range
    IB_Low_value                := SessionLow(Select_India_IB, Timezone_India)
    IB_High_value               := SessionHigh(Select_India_IB, Timezone_India)
    Opening_value               := SessionOpening(Select_India_IB, Timezone_India)
    Start_Time                  := SessionStart(Select_India_IB, Timezone_India)
    Relevant_IB_Range           := In_India_IB


else if Ticker_Oceania_Range
    IB_Low_value                := SessionLow(Select_Oceania_IB, Timezone_Oceania)
    IB_High_value               := SessionHigh(Select_Oceania_IB, Timezone_Oceania)
    Opening_value               := SessionOpening(Select_Oceania_IB, Timezone_Oceania)
    Start_Time                  := SessionStart(Select_Oceania_IB, Timezone_Oceania)
    Relevant_IB_Range           := In_Oceania_IB


else if Ticker_SouthAfrica_Range
    IB_Low_value                := SessionLow(Select_SouthAfrica_IB, Timezone_SouthAfrica)
    IB_High_value               := SessionHigh(Select_SouthAfrica_IB, Timezone_SouthAfrica)
    Opening_value               := SessionOpening(Select_SouthAfrica_IB, Timezone_SouthAfrica)
    Start_Time                  := SessionStart(Select_SouthAfrica_IB, Timezone_SouthAfrica)
    Relevant_IB_Range           := In_SouthAfrica_IB


else if Ticker_Crypto_Range
    IB_Low_value                := SessionLow(Select_Crypto_IB, Timezone_Crypto)
    IB_High_value               := SessionHigh(Select_Crypto_IB, Timezone_Crypto)
    Opening_value               := SessionOpening(Select_Crypto_IB, Timezone_Crypto)
    Start_Time                  := SessionStart(Select_Crypto_IB, Timezone_Crypto)
    Relevant_IB_Range           := In_Crypto_IB


else
    IB_Low_value                := SessionLow(Select_Universal_IB, Timezone)
    IB_High_value               := SessionHigh(Select_Universal_IB, Timezone)
    Opening_value               := SessionOpening(Select_Universal_IB, Timezone)
    Start_Time                  := SessionStart(Select_Universal_IB, Timezone)
    Relevant_IB_Range           := In_Universal_IB

    
Asia_Session_Start_Time     := SessionStart(Select_Asia_Session, Timezone_Asia)
Asia_Session_High_value     := SessionHigh(Select_Asia_Session, Timezone_Asia)
Asia_Session_Low_value      := SessionLow(Select_Asia_Session, Timezone_Asia)

PrevD_Closing_time          := PrevDayClosing_Time()
PrevD_Closing_value         := PrevDayClosing_Value()
PrevD_High_value            := PrevDayHigh_Value()
PrevD_Low_value             := PrevDayLow_Value()

//if (dayofweek == dayofweek.monday)
//    PrevD_Closing_time      := PrevDayFridayClosing_Time()
//    Day_Session_End         := PrevD_Closing_time + 172850000
//else
//    PrevD_Closing_time      := PrevDayClosing_Time()
//    Day_Session_End         := PrevD_Closing_time + 86290000




IB_Halfback_value   := (IB_High_value + IB_Low_value) / 2

if IB_Lines_Extension_alt == false
    IB_High15_value     := IB_High_value + ((IB_High_value - IB_Low_value) * 0.5)
    IB_High20_value     := IB_High_value + ((IB_High_value - IB_Low_value) * 1.0)
    IB_High25_value     := IB_High_value + ((IB_High_value - IB_Low_value) * 1.5)
    IB_High30_value     := IB_High_value + ((IB_High_value - IB_Low_value) * 2.0)
    IB_Low15_value      := IB_Low_value - ((IB_High_value - IB_Low_value) * 0.5)
    IB_Low20_value      := IB_Low_value - ((IB_High_value - IB_Low_value) * 1.0)
    IB_Low25_value      := IB_Low_value - ((IB_High_value - IB_Low_value) * 1.5)
    IB_Low30_value      := IB_Low_value - ((IB_High_value - IB_Low_value) * 2.0)
else
    IB_High15_value     := Opening_value + ((IB_High_value - Opening_value) * 1.5)
    IB_High20_value     := Opening_value + ((IB_High_value - Opening_value) * 2.0)
    IB_High25_value     := Opening_value + ((IB_High_value - Opening_value) * 2.5)
    IB_High30_value     := Opening_value + ((IB_High_value - Opening_value) * 3.0)
    IB_Low15_value      := Opening_value - ((Opening_value - IB_Low_value) * 1.5)
    IB_Low20_value      := Opening_value - ((Opening_value - IB_Low_value) * 2.0)
    IB_Low25_value      := Opening_value - ((Opening_value - IB_Low_value) * 2.5)
    IB_Low30_value      := Opening_value - ((Opening_value - IB_Low_value) * 3.0)

End_Time                := Start_Time + 86280000   //Add one complete Day minus 2 minutes in Milliseconds to extend Lines until new session starts
Asia_Session_End_Time   := Asia_Session_Start_Time + 86280000
Premarket_End_Time      := Premarket_Start_Time + 3540000 // Add 59 minutes
Day_Session_End         := PrevD_Closing_time + 86280000

//if Extend_Asia_Lines == true
    //Asia_Session_End_Time := (Asia_Session_Start_Time + 86280000)
//else
  //Asia_Session_End_Time := (Asia_Session_Start_Time + 20700000)     // During German Summertime MESZ Eurex Opening at 02:00
  //  Asia_Session_End_Time := (Asia_Session_Start_Time + 24300000)     // During German Wintertime MEZ Eurex Opening at 01:00


//####################################
// Plot Lines only x Days Back
//####################################

_MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000
lastBarDate = timestamp(year(timenow), month(timenow), dayofmonth(timenow), hour(timenow), minute(timenow), second(timenow))
thisBarDate = timestamp(year, month, dayofmonth, hour, minute, second)
daysLeft = math.floor((lastBarDate - thisBarDate) / _MILLISECONDS_IN_DAY)
In_Plot_Range = daysLeft <= Plot_x_days



//####################################
// Line Styles
//####################################


Line_Style_Function(Line_Style_Option) =>
    var string Line_Style = ""
    if Line_Style_Option == "dotted (┈)" 
        Line_Style := line.style_dotted

    else if Line_Style_Option == "dashed (╌)"
        Line_Style := line.style_dashed

    else if Line_Style_Option == "arrow left (←)"
        Line_Style := line.style_arrow_left

    else if Line_Style_Option == "arrow right (→)"
        Line_Style := line.style_arrow_right

    else if Line_Style_Option == "arrows both (↔)"
        Line_Style := line.style_arrow_both
    
    else if Line_Style_Option == "solid (─)"
        Line_Style := line.style_solid

    Line_Style


IB_Lines_Style                  = Line_Style_Function(IB_Lines_Style_Option)
IB_Lines15_Style                = Line_Style_Function(IB_Lines15_Style_Option) 
IB_Lines20_Style                = Line_Style_Function(IB_Lines20_Style_Option)
IB_Lines25_Style                = Line_Style_Function(IB_Lines25_Style_Option)
IB_Lines30_Style                = Line_Style_Function(IB_Lines30_Style_Option)  
IB_Halfback_Line_Style          = Line_Style_Function(IB_Halfback_Line_Style_Option)
Premarket_High_Line_Style       = Line_Style_Function(Premarket_High_Line_Style_Option)
Premarket_Low_Line_Style        = Line_Style_Function(Premarket_Low_Line_Style_Option)
Opening_Line_Style              = Line_Style_Function(Opening_Line_Style_Option)
PrevD_Closing_Line_Style        = Line_Style_Function(PrevD_Closing_Line_Style_Option)
PrevD_High_Line_Style           = Line_Style_Function(PrevD_High_Line_Style_Option)
PrevD_Low_Line_Style            = Line_Style_Function(PrevD_Low_Line_Style_Option)
Asia_Session_High_Line_Style    = Line_Style_Function(Asia_Session_High_Line_Style_Option)
Asia_Session_Low_Line_Style     = Line_Style_Function(Asia_Session_Low_Line_Style_Option)


//####################################
// Plots
//####################################

if Relevant_IB_Range and In_Plot_Range and timeframe.isintraday
    if Relevant_IB_Range[1]
        line.delete(IB_Low_Line)
        line.delete(IB_Low15_Line)
        line.delete(IB_Low20_Line)
        line.delete(IB_Low25_Line)
        line.delete(IB_Low30_Line)
        line.delete(IB_High_Line)
        line.delete(IB_High15_Line)
        line.delete(IB_High20_Line)
        line.delete(IB_High25_Line)
        line.delete(IB_High30_Line)
        line.delete(IB_Halfback_Line)
        line.delete(Premarket_High_Line)
        line.delete(Premarket_Low_Line)
        line.delete(Opening_Line)
        line.delete(Asia_Session_High_Line)
        line.delete(Asia_Session_Low_Line)

        label.delete(IB_Low_Label)
        label.delete(IB_Low15_Label)
        label.delete(IB_Low20_Label)
        label.delete(IB_Low25_Label)
        label.delete(IB_Low30_Label)
        label.delete(IB_High_Label)
        label.delete(IB_High15_Label)
        label.delete(IB_High20_Label)
        label.delete(IB_High25_Label)
        label.delete(IB_High30_Label)
        label.delete(IB_Halfback_Label)
        label.delete(Premarket_High_Label)
        label.delete(Premarket_Low_Label)
        label.delete(Opening_Label)
        label.delete(Asia_Session_High_Label)
        label.delete(Asia_Session_Low_Label)


//Create IB high/low  lines
    if Lines_IB_active
        IB_Low_Line         := Lines_Plot(Start_Time, IB_Low_value, End_Time, IB_Lines_Color, IB_Lines_Style, IB_Lines_width)
        IB_High_Line        := Lines_Plot(Start_Time, IB_High_value, End_Time, IB_Lines_Color, IB_Lines_Style, IB_Lines_width)

    if Lines_IB_active and Labels_active
        IB_Low_Label        := label.new(x=End_Time, y=IB_Low_value, text= "IB_L", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines_Color,Labels_Transparency), style=label.style_label_left)
        IB_High_Label       := label.new(x=End_Time, y=IB_High_value, text= "IB_H", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines_Color,Labels_Transparency), style=label.style_label_left)


    if Lines_IB_15_Extension_active
        IB_Low15_Line       := Lines_Plot(Start_Time, IB_Low15_value, End_Time, IB_Lines15_Color, IB_Lines15_Style, IB_Lines15_width)
        IB_High15_Line      := Lines_Plot(Start_Time, IB_High15_value, End_Time, IB_Lines15_Color, IB_Lines15_Style, IB_Lines15_width)

    if Lines_IB_15_Extension_active and Labels_active
        IB_Low15_Label      := label.new(x=End_Time, y=IB_Low15_value, text= "IB_L1.5", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines15_Color,Labels_Transparency), style=label.style_label_left)
        IB_High15_Label     := label.new(x=End_Time, y=IB_High15_value, text= "IB_H1.5", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines15_Color,Labels_Transparency), style=label.style_label_left)


    if Lines_IB_20_Extension_active
        IB_Low20_Line       := Lines_Plot(Start_Time, IB_Low20_value, End_Time, IB_Lines20_Color, IB_Lines20_Style, IB_Lines20_width)
        IB_High20_Line      := Lines_Plot(Start_Time, IB_High20_value, End_Time, IB_Lines20_Color, IB_Lines20_Style, IB_Lines20_width)

    if Lines_IB_20_Extension_active and Labels_active
        IB_Low20_Label      := label.new(x=End_Time, y=IB_Low20_value, text= "IB_L2.0", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines20_Color,Labels_Transparency), style=label.style_label_left)
        IB_High20_Label     := label.new(x=End_Time, y=IB_High20_value, text= "IB_H2.0", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines20_Color,Labels_Transparency), style=label.style_label_left)


    if Lines_IB_25_Extension_active
        IB_Low25_Line       := Lines_Plot(Start_Time, IB_Low25_value, End_Time, IB_Lines25_Color, IB_Lines25_Style, IB_Lines25_width)
        IB_High25_Line      := Lines_Plot(Start_Time, IB_High25_value, End_Time, IB_Lines25_Color, IB_Lines25_Style, IB_Lines25_width)

    if Lines_IB_25_Extension_active and Labels_active
        IB_Low25_Label      := label.new(x=End_Time, y=IB_Low25_value, text= "IB_L2.5", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines25_Color,Labels_Transparency), style=label.style_label_left)
        IB_High25_Label     := label.new(x=End_Time, y=IB_High25_value, text= "IB_H2.5", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines25_Color,Labels_Transparency), style=label.style_label_left)


    if Lines_IB_30_Extension_active
        IB_Low30_Line       := Lines_Plot(Start_Time, IB_Low30_value, End_Time, IB_Lines30_Color, IB_Lines30_Style, IB_Lines30_width)
        IB_High30_Line      := Lines_Plot(Start_Time, IB_High30_value, End_Time, IB_Lines30_Color, IB_Lines30_Style, IB_Lines30_width)

    if Lines_IB_30_Extension_active and Labels_active
        IB_Low30_Label      := label.new(x=End_Time, y=IB_Low30_value, text= "IB_L3.0", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines30_Color,Labels_Transparency), style=label.style_label_left)
        IB_High30_Label     := label.new(x=End_Time, y=IB_High30_value, text= "IB_H3.0", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Lines30_Color,Labels_Transparency), style=label.style_label_left)



//Create Initial Balance Halfback line
    if Lines_IB_Halfback_active
        IB_Halfback_Line    := Lines_Plot(Start_Time, IB_Halfback_value, End_Time, IB_Halfback_Line_Color, IB_Halfback_Line_Style, IB_Halfback_Line_width)


    if Lines_IB_Halfback_active and Labels_active
        IB_Halfback_Label   := label.new(x=End_Time, y=IB_Halfback_value, text= "IB_HB", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(IB_Halfback_Line_Color,Labels_Transparency), style=label.style_label_left)



//Create Premarket high/low  lines
    if Lines_Premarket_active
        Premarket_High_Line      := Lines_Plot(Premarket_Start_Time, Premarket_High_value, Premarket_End_Time, Premarket_High_Line_Color, Premarket_High_Line_Style, Premarket_Line_width)
        Premarket_Low_Line       := Lines_Plot(Premarket_Start_Time, Premarket_Low_value, Premarket_End_Time, Premarket_Low_Line_Color, Premarket_Low_Line_Style, Premarket_Line_width)

    if Lines_Premarket_active and Labels_active
        Premarket_High_Label      := label.new(x=Premarket_End_Time, y=Premarket_High_value, text= "Pmkt_H", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Premarket_High_Line_Color,Labels_Transparency), style=label.style_label_left)
        Premarket_Low_Label       := label.new(x=Premarket_End_Time, y=Premarket_Low_value, text= "Pmkt_L", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Premarket_Low_Line_Color,Labels_Transparency), style=label.style_label_left)



//Create Opening Line
    if Lines_Opening_active
        Opening_Line        := Lines_Plot(Start_Time, Opening_value, End_Time, Opening_Line_Color, Opening_Line_Style, Opening_Line_width)
       
    if Lines_Opening_active and Labels_active
        Opening_Label       := label.new(x=End_Time, y=Opening_value, text= "Open", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Opening_Line_Color,Labels_Transparency), style=label.style_label_left)
   

//Create Asia Session high/low  lines
    if Lines_Asia_Session_active
        Asia_Session_High_Line      := Lines_Plot(Asia_Session_Start_Time, Asia_Session_High_value, Asia_Session_End_Time, Asia_Session_High_Line_Color, Asia_Session_High_Line_Style, Asia_Line_width)
        Asia_Session_Low_Line       := Lines_Plot(Asia_Session_Start_Time, Asia_Session_Low_value, Asia_Session_End_Time, Asia_Session_Low_Line_Color, Asia_Session_Low_Line_Style, Asia_Line_width)

    if Lines_Asia_Session_active and Labels_active
        Asia_Session_High_Label      := label.new(x=Asia_Session_End_Time, y=Asia_Session_High_value, text= "Asia_H", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Asia_Session_High_Line_Color,Labels_Transparency), style=label.style_label_left)
        Asia_Session_Low_Label       := label.new(x=Asia_Session_End_Time, y=Asia_Session_Low_value, text= "Asia_L", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Asia_Session_Low_Line_Color,Labels_Transparency), style=label.style_label_left)


//Create Premarket Session high/low  lines
else if Relevant_Premarket and In_Plot_Range and timeframe.isintraday
    if Relevant_Premarket[1]
        line.delete(Premarket_High_Line)
        line.delete(Premarket_Low_Line)
        label.delete(Premarket_High_Label)
        label.delete(Premarket_Low_Label)

        if Lines_Premarket_active
            Premarket_High_Line      := Lines_Plot(Premarket_Start_Time, Premarket_High_value, Premarket_End_Time, Premarket_High_Line_Color, Premarket_High_Line_Style, Premarket_Line_width)
            Premarket_Low_Line       := Lines_Plot(Premarket_Start_Time, Premarket_Low_value, Premarket_End_Time, Premarket_Low_Line_Color, Premarket_Low_Line_Style, Premarket_Line_width)

        if Lines_Premarket_active and Labels_active
            Premarket_High_Label      := label.new(x=Premarket_End_Time, y=Premarket_High_value, text= "Pmkt_H", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Premarket_High_Line_Color,Labels_Transparency), style=label.style_label_left)
            Premarket_Low_Label       := label.new(x=Premarket_End_Time, y=Premarket_Low_value, text= "Pmkt_L", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Premarket_Low_Line_Color,Labels_Transparency), style=label.style_label_left)


//Create Asia Session high/low  lines
else if In_Asia_Session and In_Plot_Range and timeframe.isintraday
    if In_Asia_Session[1]
        line.delete(Asia_Session_High_Line)
        line.delete(Asia_Session_Low_Line)
        label.delete(Asia_Session_High_Label)
        label.delete(Asia_Session_Low_Label)

        if Lines_Asia_Session_active
            Asia_Session_High_Line      := Lines_Plot(Asia_Session_Start_Time, Asia_Session_High_value, Asia_Session_End_Time, Asia_Session_High_Line_Color, Asia_Session_High_Line_Style, Asia_Line_width)
            Asia_Session_Low_Line       := Lines_Plot(Asia_Session_Start_Time, Asia_Session_Low_value, Asia_Session_End_Time, Asia_Session_Low_Line_Color, Asia_Session_Low_Line_Style, Asia_Line_width)

        if Lines_Asia_Session_active and Labels_active
            Asia_Session_High_Label      := label.new(x=Asia_Session_End_Time, y=Asia_Session_High_value, text= "Asia_H", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Asia_Session_High_Line_Color,Labels_Transparency), style=label.style_label_left)
            Asia_Session_Low_Label       := label.new(x=Asia_Session_End_Time, y=Asia_Session_Low_value, text= "Asia_L", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(Asia_Session_Low_Line_Color,Labels_Transparency), style=label.style_label_left)


//Plot Previous Day Lines
newDay = dayofmonth != dayofmonth[1]
if newDay and In_Plot_Range and timeframe.isintraday

    if PrevD_Lines_Closing_active
        PrevD_Closing_Line        := Lines_Plot(PrevD_Closing_time, PrevD_Closing_value, Day_Session_End, PrevD_Closing_Line_Color, PrevD_Closing_Line_Style, PrevD_Closing_Line_width)

    if PrevD_Lines_Closing_active and Labels_active
        PrevD_Closing_Label       := label.new(x=Day_Session_End, y=PrevD_Closing_value, text= "PrevD_C", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(PrevD_Closing_Line_Color,Labels_Transparency), style=label.style_label_left)
   
    if PrevD_Lines_High_active
        PrevD_High_Line        := Lines_Plot(PrevD_Closing_time, PrevD_High_value, Day_Session_End, PrevD_High_Line_Color, PrevD_High_Line_Style, PrevD_High_Line_width)

    if PrevD_Lines_High_active and Labels_active
        PrevD_High_Label       := label.new(x=Day_Session_End, y=PrevD_High_value, text= "PrevD_H", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(PrevD_High_Line_Color,Labels_Transparency), style=label.style_label_left)
   
    if PrevD_Lines_Low_active
        PrevD_Low_Line        := Lines_Plot(PrevD_Closing_time, PrevD_Low_value, Day_Session_End, PrevD_Low_Line_Color, PrevD_Low_Line_Style, PrevD_Low_Line_width)

    if PrevD_Lines_Low_active and Labels_active
        PrevD_Low_Label       := label.new(x=Day_Session_End, y=PrevD_Low_value, text= "PrevD_L", xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.black,100), textalign= text.align_right, textcolor=color.new(PrevD_Low_Line_Color,Labels_Transparency), style=label.style_label_left)
   

//####################################
// Plots end!
//####################################


//####################################
// Alert Conditions
//####################################

crossover_IB_High           = ta.crossover(close, IB_High_value) and not Relevant_IB_Range
crossunder_IB_High          = ta.crossunder(close, IB_High_value) and not Relevant_IB_Range
crossover_IB_High15         = ta.crossover(close, IB_High15_value) and not Relevant_IB_Range
crossunder_IB_High15        = ta.crossunder(close, IB_High15_value) and not Relevant_IB_Range
crossover_IB_High20         = ta.crossover(close, IB_High20_value) and not Relevant_IB_Range
crossunder_IB_High20        = ta.crossunder(close, IB_High20_value) and not Relevant_IB_Range
crossover_IB_High25         = ta.crossover(close, IB_High25_value) and not Relevant_IB_Range
crossunder_IB_High25        = ta.crossunder(close, IB_High25_value) and not Relevant_IB_Range
crossover_IB_High30         = ta.crossover(close, IB_High30_value) and not Relevant_IB_Range
crossunder_IB_High30        = ta.crossunder(close, IB_High30_value) and not Relevant_IB_Range
crossover_IB_Low            = ta.crossover(close, IB_Low_value) and not Relevant_IB_Range
crossunder_IB_Low           = ta.crossunder(close, IB_Low_value) and not Relevant_IB_Range
crossover_IB_Low15          = ta.crossover(close, IB_Low15_value) and not Relevant_IB_Range
crossunder_IB_Low15         = ta.crossunder(close, IB_Low15_value) and not Relevant_IB_Range
crossover_IB_Low20          = ta.crossover(close, IB_Low20_value) and not Relevant_IB_Range
crossunder_IB_Low20         = ta.crossunder(close, IB_Low20_value) and not Relevant_IB_Range
crossover_IB_Low25          = ta.crossover(close, IB_Low25_value) and not Relevant_IB_Range
crossunder_IB_Low25         = ta.crossunder(close, IB_Low25_value) and not Relevant_IB_Range
crossover_IB_Low30          = ta.crossover(close, IB_Low30_value) and not Relevant_IB_Range
crossunder_IB_Low30         = ta.crossunder(close, IB_Low30_value) and not Relevant_IB_Range
crossover_IB_Halfback       = ta.crossover(close, IB_Halfback_value) and not Relevant_IB_Range
crossunder_IB_Halfback      = ta.crossunder(close, IB_Halfback_value) and not Relevant_IB_Range
crossover_Premarket_High    = ta.crossover(close, Premarket_High_value) and not Relevant_Premarket
crossunder_Premarket_High   = ta.crossunder(close, Premarket_High_value) and not Relevant_Premarket
crossover_Premarket_Low     = ta.crossover(close, Premarket_Low_value) and not Relevant_Premarket
crossunder_Premarket_Low    = ta.crossunder(close, Premarket_Low_value) and not Relevant_Premarket
crossover_Opening           = ta.crossover(close, Opening_value) and not Relevant_IB_Range
crossunder_Opening          = ta.crossunder(close, Opening_value) and not Relevant_IB_Range
crossover_PrevDay_Closing   = ta.crossover(close, PrevD_Closing_value)
crossunder_PrevDay_Closing  = ta.crossunder(close, PrevD_Closing_value)
crossover_PrevDay_High      = ta.crossover(close, PrevD_High_value)
crossunder_PrevDay_High     = ta.crossunder(close, PrevD_High_value)
crossover_PrevDay_Low       = ta.crossover(close, PrevD_Low_value)
crossunder_PrevDay_Low      = ta.crossunder(close, PrevD_Low_value)
crossover_Asia_Low          = ta.crossover(close, Asia_Session_Low_value) and not In_Asia_Session
crossunder_Asia_Low         = ta.crossunder(close, Asia_Session_Low_value) and not In_Asia_Session
crossover_Asia_High          = ta.crossover(close, Asia_Session_High_value) and not In_Asia_Session
crossunder_Asia_High         = ta.crossunder(close, Asia_Session_High_value) and not In_Asia_Session


alertcondition(crossover_IB_High, "Crossover IB High Line","Crossover IB High Line")
alertcondition(crossunder_IB_High, "Crossunder IB High Line","Crossunder IB High Line")
alertcondition(crossover_IB_High15, "Crossover IB High 1.5 Line","Crossover IB High 1.5 Line")
alertcondition(crossunder_IB_High15, "Crossunder IB High 1.5 Line","Crossunder IB High 1.5 Line")
alertcondition(crossover_IB_High20, "Crossover IB High 2.0 Line","Crossover IB High 2.0 Line")
alertcondition(crossunder_IB_High20, "Crossunder IB High 2.0 Line","Crossunder IB High 2.0 Line")
alertcondition(crossover_IB_High25, "Crossover IB High 2.5 Line","Crossover IB High 2.5 Line")
alertcondition(crossunder_IB_High25, "Crossunder IB High 2.5 Line","Crossunder IB High 2.5 Line")
alertcondition(crossover_IB_High30, "Crossover IB High 3.0 Line","Crossover IB High 3.0 Line")
alertcondition(crossunder_IB_High30, "Crossunder IB High 3.0 Line","Crossunder IB High 3.0 Line")
alertcondition(crossover_IB_Low, "Crossover IB Low Line","Crossover IB Low Line")
alertcondition(crossunder_IB_Low, "Crossunder IB Low Line","Crossunder IB Low Line")
alertcondition(crossover_IB_Low15, "Crossover IB Low 1.5 Line","Crossover IB Low 1.5 Line")
alertcondition(crossunder_IB_Low15, "Crossunder IB Low 1.5 Line","Crossunder IB Low 1.5 Line")
alertcondition(crossover_IB_Low20, "Crossover IB Low 2.0 Line","Crossover IB Low 2.0 Line")
alertcondition(crossunder_IB_Low20, "Crossunder IB Low 2.0 Line","Crossunder IB Low 2.0 Line")
alertcondition(crossover_IB_Low25, "Crossover IB Low 2.5 Line","Crossover IB Low 2.5 Line")
alertcondition(crossunder_IB_Low25, "Crossunder IB Low 2.5 Line","Crossunder IB Low 2.5 Line")
alertcondition(crossover_IB_Low30, "Crossover IB Low 3.0 Line","Crossover IB Low 3.0 Line")
alertcondition(crossunder_IB_Low30, "Crossunder IB Low 3.0 Line","Crossunder IB Low 3.0 Line")
alertcondition(crossover_IB_Halfback, "Crossover IB Halfback Line","Crossover IB Halfback Line")
alertcondition(crossunder_IB_Halfback, "Crossunder IB Halfback Line","Crossunder IB Halfback Line")
alertcondition(crossover_Premarket_High, "Crossover Premarket High Line","Crossover Premarket High Line")
alertcondition(crossunder_Premarket_High, "Crossunder Premarket High Line","Crossunder Premarket High Line")
alertcondition(crossover_Premarket_Low, "Crossover Premarket Low Line","Crossover Premarket Low Line")
alertcondition(crossunder_Premarket_Low, "Crossunder Premarket Low Line","Crossunder Premarket Low Line")
alertcondition(crossover_Opening, "Crossover Opening Line","Crossover Opening Line")
alertcondition(crossunder_Opening, "Crossunder Opening Line","Crossunder Opening Line")
alertcondition(crossover_PrevDay_Closing, "Crossover Previous Day Closing Line","Crossover Previous Day Closing Line")
alertcondition(crossunder_PrevDay_Closing, "Crossunder Previous Day Closing Line","Crossunder Previous Day Closing Line")
alertcondition(crossover_PrevDay_High, "Crossover Previous Day High Line","Crossover Previous Day High Line")
alertcondition(crossunder_PrevDay_High, "Crossunder Previous Day High Line","Crossunder Previous Day High Line")
alertcondition(crossover_PrevDay_Low, "Crossover Previous Day Low Line","Crossover Previous Day Low Line")
alertcondition(crossunder_PrevDay_Low, "Crossunder Previous Day Low Line","Crossunder Previous Day Low Line")
alertcondition(crossover_Asia_High, "Crossover Asia High Line","Crossover Asia High Line")
alertcondition(crossunder_Asia_High, "Crossunder Asia High Line","Crossunder Asia High Line")
alertcondition(crossover_Asia_Low, "Crossover Asia Low Line","Crossover Asia Low Line")
alertcondition(crossunder_Asia_Low, "Crossunder Asia Low Line","Crossunder Asia Low Line")


//####################################
// Alert Conditions end!
//####################################


//####################################
// Data checks
//####################################



//dt = time - time[1]
//if barstate.islast and Lines_IB_active and timeframe.isintraday
//    label.new(time + 3*dt, close, str.tostring(Start_Time), xloc=xloc.bar_time)
    
 //   label.new(time + 3*dt, close, str.tostring(Lines_IB_active), xloc=xloc.bar_time)



//if barstate.islastconfirmedhistory
//    label.new(x=bar_index + 2, y=close, style=label.style_label_left,
//         color=color.new(color.yellow, 80), size=size.large, 
//         text=syminfo.ticker + " has this data" + 
//             "\nsource/exchange prefix:\n" + syminfo.prefix)


//  label.new(time + 3*dt, close, str.tostring(Lines_IB_active), xloc=xloc.bar_time)