JustaBox_NY_Lex
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LexingtonStanley

//@version=5
//{ Inputs
indicator("JustaBox_NY", overlay=true, max_boxes_count = 500, max_labels_count = 500,  max_lines_count = 500 )
dataalert    = input.bool(false,"Spreadsheet Alert", "READ  THIS: Set chart to UTC -5 and 5 minute time period \n\nSends an alert with data for each session in an easy to add to excel format, alert system is limited to 4096 characters of text which will give you about 10 days of data at a time and it wont work if replay mode is turned on, thats a trading view limitation.\n\nLIMITATION: you may get an array error, this is because the loops need a full day to resolve, if 'Session to Session' is unticked the loops resolve at the start of the next session of the same name, so for NY, loop runs 10:30 - 09:30  the next day. In 'manual date range' you would make sure not to start or end on a weekend or bank holiday and use 10:15 to 10:15 for start and end.\n\nOnce turned on set an alert using the three dots on the indicator settings bar, sometimes takes a minute, make sure send to email is turned on.\n\nFrom your email, copy everything the first time, (the following times you dont need to copy the titles) then paste into cell 'A1' in excel.\n\nSelect that cell and find 'text to columns' in excels Data tab, select 'delineated' and select only 'semicolons' click finish. \n\nSelect all of row 1 and copy it, then rightclick in cell A2 and select 'Paste-transpose', this will seperate the days into rows.\n\nThen select A2 down to the last populated cell and go back to 'text to columns'... use delineated again but this time turn off semicolon and use only 'commas', click finish. \n\nVoila.\n\nHistoric Data colloction is limited to how far you can look back on that symbol on a 5 minute chart, for pro+ its 20000 bars or about 72 trading days\n this indicator only gives data for NY session use other two indicators JustaBox_LDN and JustaBox_TKO to pull tokyo and london data  otherwise functionality is the same. (trying to pull data into an alert from more than one loop hit a limit)")     
sessiontosession = input.bool(false, "Session to Session", "Session to Session:\nSets whether the backtest runs each days test for 23 hours until the start of the next session of the same name e.g. NY to NY or whether it tests until the start of the next logical session e.g. NY to Tokyo, if ticked it runs to next logical session, unticked the full day, each option includes an identifier for each days data so you can seperate the two in excel later")
symbol       = input.string("US500", "Symbol Identifier for Data Alert", tooltip="What you enter here will be exported with the rest of the data as a symbol/pair identifier for each alert so you can filter by symbol later on")
timeish      = input.bool(false,"Manual Date Range", tooltip = "Set chart to UTC -5. If using data alert, make sure not to start or finish on weekend or bank holiday and set start and end times to middle of session you want")
start        = input.time(timestamp("19 December 2022 1000, gmt-5"))
end          = input.time(timestamp("28 December 2022 1000, gmt-5"))
start2       = timenow - (((1000*60)*60)*24)*11
end2         = timenow
nytrue       = input.bool(true ,"NY Session",inline  = "session")
boxlabel     = input.float(20.0, "Top Label Height",inline = "labelheight", tooltip = "Labels mainly added to check code was working, can be useful for visual backtesting or turned off, these set how far above or below the session box they sit in price.")
sessionlabel = input.float(10.0, "Btm Label Height",inline = "labelheight",tooltip = "Labels mainly added to check code was working, can be useful for visual backtesting or turned off, these set how far above or below the session box they sit in price.")
ldntrue      = input.bool(false,"London Session",inline  = "session")
tkotrue      = input.bool(false,"Tokio Session",inline  = "session")
stdlevels    = input.bool(true, "Show STD Levels")
labelson     = input.bool(true ,"Session Labels",inline  = "labels")
fiblabels    = input.bool(false,"STD Level and Price Labels",inline  = "labels")
colorcandles = input.bool(true, "Color Candles", tooltip = "When on candles are colored differently if you get a buy or sell symbol they are also on a gradient which changes color the further from the mid point of the daily range they get. May only work for the NY session")
nycolor1     = input.color(color.green,"NY Color 1",inline  = "nycolor")
nycolor2     = input.color(color.rgb(83, 86, 250),"NY Color 2",inline  = "nycolor")
ldncolor1    = input.color(color.rgb(253, 1, 14),"London Color 1",inline  = "ldcolor")
ldncolor2    = input.color(color.rgb(208, 255, 0),"London Color 2",inline  = "ldcolor")
tycolor1     = input.color(color.rgb(2, 250, 250),"Tokyo Color 1",inline  = "tycolor")
tycolor2     = input.color(color.rgb(162, 0, 255),"Tokyo Color 2",inline  = "tycolor")
ipdaon       = input.bool(false, "60 Day Highs and Lows", tooltip = "Crude attempt and marking interbank highs and lows, marks 3 highs and 3 lows, one each from 10-20 days, 20-40 and 40 to 59 days ago(59 was limit of lookback on pro subscription, may throw an error if not enough history")
//}
//{ Initial Variables and Arrays
InSession(sessionTime, sessionTimeZone=syminfo.timezone) =>
    not na(time(timeframe.period, sessionTime, sessionTimeZone))
arraysess  = InSession("1025-1030" , "GMT-5")
prearray1  = InSession("1020-1025" , "GMT-5")
prearray3  = InSession("1920-1925" , "GMT-5")
prearray2  = InSession("0350-0355" , "GMT-5")
array1off  = InSession("0925-0930" , "GMT-5")
array2off  = InSession("0255-0300" , "GMT-5")
array3off  = InSession("1825-1830" , "GMT-5")
opensess1  = InSession("0930-0935" , "GMT-5")
opensess3  = InSession("1830-1835" , "GMT-5")
opensess2  = InSession("0300-0305" , "GMT-5")
arraysess2 = InSession("0355-0400" , "GMT-5")
arraysess3 = InSession("1925-1930" , "GMT-5")
nysess     = InSession("0930-1030" , "GMT-5")
london     = InSession("0300-0400" , "GMT-5")
tokio      = InSession("1830-1930" , "GMT-5")
var int arrayplusz      = 0
var int arrayplusz2      = 0
var int arrayplusz3      = 0
var float  nyopen       = na
var float  nyopen2      = na
var float  nyclose      = na
var float  nyclose2     = na
var float  ldnopen      = na
var float  ldnopen2     = na
var float  ldnclose     = na
var float  ldnclose2    = na
var float  tyopen       = na
var float  tyopen2      = na
var float  tyclose      = na
var float  tyclose2     = na
bool   indate           = na
box    boxy             = na
box    boxy2            = na
box    boxy3            = na
box    boxy4            = na
box    boxy5            = na
box    boxy6            = na
box    boxy7            = na
box    boxy8            = na
label  label1           = na
label  label2           = na 
label  label3           = na 
label  label4           = na 
label  label5           = na 
label  label6           = na 
label  label7           = na 
label  label8           = na
var int bartimesignal = na  
var int bartimesignal2 = na  
var int bartimesignal3 = na  
label  linelabel1       = na
label  linelabel2       = na
label  linelabel3       = na
label  linelabel4       = na
label  linelabel5       = na
label  linelabel6       = na
label  linelabel7       = na
label  linelabel8       = na
label  linelabel9       = na
label  linelabel10      = na
label  linelabel11      = na
label  linelabel12      = na
label  linelabel13      = na
label  linelabel14      = na
label  linelabel15      = na
label  linelabel16      = na
label  linelabel17      = na
line   usline1          = na
line   usline2          = na
line   usline3          = na
line   usline4          = na
line   usline5          = na
line   usline6          = na
line   usline7          = na
line   usline8          = na
line   usline9          = na
line   usline10         = na
line   usline11         = na
float  top2             = na 
float  btm2             = na 
line   usline12         = na
line   usline13         = na
line   usline14         = na
line   usline15         = na
line   usline16         = na
line   usline17         = na
float  fib1             = na
float  fib2             = na
float  fib3             = na
float  fib4             = na
float  fib5             = na
float  fib6             = na
float  fib7             = na
float  fib8             = na
float  fib9             = na
float  fib10            = na
float  fib11            = na
float  fib12            = na
float  fib13            = na
var int fib1x           = na
var int fib1xx          = na
var int fib2x           = na
var int fib3x           = na
var int fib4x           = na
var int fib5x           = na
var int fib6x           = na
var int fib7x           = na
var int fib8x           = na
var int fib9x           = na
var int fib10x          = na
var int fib11x          = na
var int fib12x          = na
var int fib13x          = na
var int top2x           = na
var int top2xx          = na
var int btm2x           = na
var int btm2xx          = na
var int topx            = na
var int bottomx         = na
var int fib1x2           = na
var int fib1xx2          = na
var int fib2x2           = na
var int fib3x2           = na
var int fib4x2           = na
var int fib5x2           = na
var int fib6x2           = na
var int fib7x2           = na
var int fib8x2           = na
var int fib9x2           = na
var int fib10x2          = na
var int fib11x2          = na
var int fib12x2          = na
var int fib13x2          = na
var int top2x2            = na
var int top2xx2           = na
var int btm2x2            = na
var int btm2xx2          = na
var int topx2            = na
var int bottomx2         = na
var int fib1x3           = na
var int fib1xx3          = na
var int fib2x3           = na
var int fib3x3           = na
var int fib4x3           = na
var int fib5x3           = na
var int fib6x3           = na
var int fib7x3           = na
var int fib8x3           = na
var int fib9x3           = na
var int fib10x3          = na
var int fib11x3          = na
var int fib12x3          = na
var int fib13x3          = na
var int top2x3           = na
var int top2xx3          = na
var int btm2x3           = na
var int btm2xx3          = na
var int topx3            = na
var int bottomx3         = na
float  toplabelprice    = na
float  bottomlabelprice = na
float  clrmax           = na
float  clrmax2          = na
float  clrmax3          = na
float  clrmax4          = na
float  clrmin           = na
float  clrmin2          = na
float  clrmin3          = na
float  clrmin4          = na
bool   topcross         = na
bool   bottomcross      = na
bool   topcross2         = na
bool   bottomcross2      = na
bool   topcross3         = na
bool   bottomcross3      = na
var bool array1         = na
var bool array2         = na
var bool array3         = na
var bool array4         = na
var bool array5         = na
var bool array6         = na
var bool topb           = na 
var bool top2b          = na
var bool top2bb         = na
var bool bottomb        = na
var bool btm2b          = na
var bool btm2bb         = na
var bool fib1b          = na
var bool fib1bb         = na
var bool fib2b          = na
var bool fib3b          = na
var bool fib4b          = na
var bool fib5b          = na
var bool fib6b          = na
var bool fib7b          = na
var bool fib8b          = na
var bool fib9b          = na
var bool fib10b         = na
var bool fib11b         = na
var bool fib12b         = na
var bool fib13b         = na
var bool topb2          = na 
var bool top2b2         = na
var bool top2bb2        = na
var bool bottomb2       = na
var bool btm2b2         = na
var bool btm2bb2        = na
var bool fib1b2         = na
var bool fib1bb2        = na
var bool fib2b2         = na
var bool fib3b2         = na
var bool fib4b2         = na
var bool fib5b2         = na
var bool fib6b2         = na
var bool fib7b2         = na
var bool fib8b2         = na
var bool fib9b2         = na
var bool fib10b2        = na
var bool fib11b2        = na
var bool fib12b2        = na
var bool fib13b2        = na
var bool topb3          = na 
var bool top2b3         = na
var bool top2bb3        = na
var bool bottomb3       = na
var bool btm2b3         = na
var bool btm2bb3        = na
var bool fib1b3         = na
var bool fib1bb3        = na
var bool fib2b3         = na
var bool fib3b3         = na
var bool fib4b3         = na
var bool fib5b3         = na
var bool fib6b3         = na
var bool fib7b3         = na
var bool fib8b3         = na
var bool fib9b3         = na
var bool fib10b3        = na
var bool fib11b3        = na
var bool fib12b3        = na
var bool fib13b3        = na
var int  date        = na
var int  date2        = na
var int  date3        = na
string NYID             = "NY"
string LondonID         = "London"
string TokioID          = "Tokio"
string FrankfurtID      = "Frankfurt"
string weekday          = na
string sesslength       = na
var    dates            = array.new_int()
var    dates2            = array.new_int()
var    dates3            = array.new_int()

var    signaltimea       = array.new_int()
var    signaltime2       = array.new_int()
var    signaltime3       = array.new_int()
var    nybarindexa      = array.new_int()
var    ldnbarindexa      = array.new_int()
var    tybarindexa      = array.new_int()
var    top2xa      = array.new_int()
var    top2xxa      = array.new_int()
var    topxa       = array.new_int()
var    btm2xa      = array.new_int()
var    btm2xxa      = array.new_int()
var    bottomxa    = array.new_int()
var    fib1xa      = array.new_int()
var    fib1xxa      = array.new_int()
var    fib2xa      = array.new_int()
var    fib3xa      = array.new_int()
var    fib4xa      = array.new_int()
var    fib5xa      = array.new_int()
var    fib6xa      = array.new_int()
var    fib7xa      = array.new_int()
var    fib8xa      = array.new_int()
var    fib9xa      = array.new_int()
var    fib10xa     = array.new_int()
var    fib11xa     = array.new_int()
var    fib12xa     = array.new_int()
var    fib13xa     = array.new_int()
var    top2xa2      = array.new_int()
var    top2xxa2      = array.new_int()
var    topxa2       = array.new_int()
var    btm2xa2      = array.new_int()
var    btm2xxa2      = array.new_int()
var    bottomxa2    = array.new_int()
var    fib1xa2      = array.new_int()
var    fib1xxa2      = array.new_int()
var    fib2xa2      = array.new_int()
var    fib3xa2      = array.new_int()
var    fib4xa2      = array.new_int()
var    fib5xa2      = array.new_int()
var    fib6xa2      = array.new_int()
var    fib7xa2      = array.new_int()
var    fib8xa2      = array.new_int()
var    fib9xa2      = array.new_int()
var    fib10xa2     = array.new_int()
var    fib11xa2    = array.new_int()
var    fib12xa2     = array.new_int()
var    fib13xa2     = array.new_int()
var    top2xa3      = array.new_int()
var    top2xxa3      = array.new_int()
var    topxa3       = array.new_int()
var    btm2xa3      = array.new_int()
var    btm2xxa3      = array.new_int()
var    bottomxa3    = array.new_int()
var    fib1xa3      = array.new_int()
var    fib1xxa3      = array.new_int()
var    fib2xa3      = array.new_int()
var    fib3xa3      = array.new_int()
var    fib4xa3      = array.new_int()
var    fib5xa3      = array.new_int()
var    fib6xa3      = array.new_int()
var    fib7xa3      = array.new_int()
var    fib8xa3     = array.new_int()
var    fib9xa3      = array.new_int()
var    fib10xa3     = array.new_int()
var    fib11xa3     = array.new_int()
var    fib12xa3     = array.new_int()
var    fib13xa3     = array.new_int()
var    IDR_close_array  = array.new_float()
var    colorgradarray   = array.new_float()
var    sessionID        = array.new_string()
var    sessionID2        = array.new_string()
var    sessionID3        = array.new_string()
var    signaldira        = array.new_string()
var    signaldira2        = array.new_string()
var    signaldira3        = array.new_string()
var    symbola        = array.new_string()
var    nyopenarray1     = array.new_float()
var    nyopenarray2     = array.new_float()
var    nyclosearray1    = array.new_float()
var    nyclosearray2    = array.new_float()
var    ldnopenarray1     = array.new_float()
var    ldnopenarray2     = array.new_float()
var    ldnclosearray1    = array.new_float()
var    ldnclosearray2    = array.new_float()
var    tyopenarray1     = array.new_float()
var    tyopenarray2     = array.new_float()
var    tyclosearray1    = array.new_float()
var    tyclosearray2    = array.new_float()
var    fib1a            = array.new_bool()
var    fib1aa           = array.new_bool()
var    fib2a            = array.new_bool()
var    fib3a            = array.new_bool()
var    fib4a            = array.new_bool()
var    fib5a            = array.new_bool()
var    fib6a            = array.new_bool()
var    fib7a            = array.new_bool()
var    fib8a            = array.new_bool()
var    fib9a            = array.new_bool()
var    fib10a           = array.new_bool()
var    fib11a           = array.new_bool()
var    fib12a           = array.new_bool()
var    fib13a           = array.new_bool()
var    top2a            = array.new_bool()
var    top2aa           = array.new_bool()
var    topa             = array.new_bool()
var    bottoma          = array.new_bool()
var    btm2a            = array.new_bool()
var    btm2aa           = array.new_bool()
var    fib1a2            = array.new_bool()
var    fib1aa2           = array.new_bool()
var    fib2a2            = array.new_bool()
var    fib3a2            = array.new_bool()
var    fib4a2            = array.new_bool()
var    fib5a2            = array.new_bool()
var    fib6a2            = array.new_bool()
var    fib7a2            = array.new_bool()
var    fib8a2            = array.new_bool()
var    fib9a2            = array.new_bool()
var    fib10a2           = array.new_bool()
var    fib11a2           = array.new_bool()
var    fib12a2           = array.new_bool()
var    fib13a2           = array.new_bool()
var    top2a2            = array.new_bool()
var    top2aa2           = array.new_bool()
var    topa2             = array.new_bool()
var    bottoma2          = array.new_bool()
var    btm2a2            = array.new_bool()
var    btm2aa2           = array.new_bool()
var    fib1a3            = array.new_bool()
var    fib1aa3           = array.new_bool()
var    fib2a3            = array.new_bool()
var    fib3a3            = array.new_bool()
var    fib4a3            = array.new_bool()
var    fib5a3            = array.new_bool()
var    fib6a3            = array.new_bool()
var    fib7a3            = array.new_bool()
var    fib8a3            = array.new_bool()
var    fib9a3            = array.new_bool()
var    fib10a3           = array.new_bool()
var    fib11a3           = array.new_bool()
var    fib12a3          = array.new_bool()
var    fib13a3           = array.new_bool()
var    top2a3            = array.new_bool()
var    top2aa3           = array.new_bool()
var    topa3             = array.new_bool()
var    bottoma3          = array.new_bool()
var    btm2a3            = array.new_bool()
var    btm2aa3           = array.new_bool()
var    ptopz            = array.new_float()
var    pbottomz         = array.new_float()
var    ptop2z           = array.new_float()
var    pbtm2z           = array.new_float()
var    p2topz           = array.new_float()
var    p2bottomz        = array.new_float()
var    p2top2z          = array.new_float()
var    p2btm2z          = array.new_float()
var    p3topz           = array.new_float()
var    p3bottomz        = array.new_float()
var    p3top2z          = array.new_float()
var    p3btm2z          = array.new_float()
var    topz             = array.new_float()
var    bottomz          = array.new_float()
var    top2z            = array.new_float()
var    btm2z            = array.new_float()
var    fib1z            = array.new_float()
var    fib2z            = array.new_float()
var    fib3z            = array.new_float()
var    fib4z            = array.new_float()
var    fib5z            = array.new_float()
var    fib6z            = array.new_float()
var    fib7z            = array.new_float()
var    fib8z            = array.new_float()
var    fib9z            = array.new_float()
var    fib10z           = array.new_float()
var    fib11z           = array.new_float()
var    fib12z           = array.new_float()
var    fib13z           = array.new_float()
var    t2opz             = array.new_float()
var    b2ottomz          = array.new_float()
var    t2op2z            = array.new_float()
var    b2tm2z            = array.new_float()
var    f2ib1z            = array.new_float()
var    f2ib2z            = array.new_float()
var    f2ib3z            = array.new_float()
var    f2ib4z            = array.new_float()
var    f2ib5z            = array.new_float()
var    f2ib6z            = array.new_float()
var    f2ib7z            = array.new_float()
var    f2ib8z            = array.new_float()
var    f2ib9z            = array.new_float()
var    f2ib10z           = array.new_float()
var    f2ib11z           = array.new_float()
var    f2ib12z           = array.new_float()
var    f2ib13z           = array.new_float()
var    t3opz             = array.new_float()
var    b3ottomz          = array.new_float()
var    t3op2z            = array.new_float()
var    b3tm2z            = array.new_float()
var    f3ib1z            = array.new_float()
var    f3ib2z            = array.new_float()
var    f3ib3z            = array.new_float()
var    f3ib4z            = array.new_float()
var    f3ib5z            = array.new_float()
var    f3ib6z            = array.new_float()
var    f3ib7z            = array.new_float()
var    f3ib8z            = array.new_float()
var    f3ib9z            = array.new_float()
var    f3ib10z           = array.new_float()
var    f3ib11z           = array.new_float()
var    f3ib12z           = array.new_float()
var    f3ib13z           = array.new_float()
var    topz2            = array.new_float()
var    bottomz2         = array.new_float()
var    top2z2           = array.new_float()
var    btm2z2           = array.new_float()
var    fib1z2           = array.new_float()
var    fib2z2           = array.new_float()
var    fib3z2           = array.new_float()
var    fib4z2           = array.new_float()
var    fib5z2           = array.new_float()
var    fib6z2           = array.new_float()
var    fib7z2           = array.new_float()
var    fib8z2           = array.new_float()
var    fib9z2           = array.new_float()
var    fib10z2          = array.new_float()
var    fib11z2          = array.new_float()
var    fib12z2          = array.new_float()
var    fib13z2          = array.new_float()
var    topz3            = array.new_float()
var    bottomz3         = array.new_float()
var    top2z3           = array.new_float()
var    btm2z3           = array.new_float()
var    fib1z3           = array.new_float()
var    fib2z3           = array.new_float()
var    fib3z3           = array.new_float()
var    fib4z3           = array.new_float()
var    fib5z3           = array.new_float()
var    fib6z3           = array.new_float()
var    fib7z3           = array.new_float()
var    fib8z3           = array.new_float()
var    fib9z3           = array.new_float()
var    fib10z3          = array.new_float()
var    fib11z3          = array.new_float()
var    fib12z3          = array.new_float()
var    fib13z3          = array.new_float()
var    highpa           = array.new_float()
var    highpa2          = array.new_float()
var    highpa3          = array.new_float()
var    lowpa            = array.new_float()
var    lowpa2           = array.new_float()
var    lowpa3           = array.new_float()
var    nydayopena       = array.new_float()
var    barcounta        = array.new_bool()
var    sesslengtha      = array.new_string()
float highp = na
float lowp = na
var int  arrayplus1       = 0 
var int  arrayplus2       = 0 
var int  arrayplus3       = 0 
var bool candlecolorup    = na
var bool candlecolorup2   = na
var bool candlecolorup3   = na
var bool candlecolordown  = na
var bool candlecolordown2 = na
var bool candlecolordown3 = na
var bool startarray       = false
var bool startarray2      = false
var bool startarray3       = false
var bool nycleanarray1    = na
var bool nycleanarray2    = na
var bool ldncleanarray1 = na
var bool ldncleanarray2 = na
var bool tycleanarray1 = na
var bool tycleanarray2 = na
var bool barcount  = na
var bool barcount2 = na
var bool barcount3 = na
int rightlinex            = na
var int nybarindex            = na
var int ldnbarindex            = na
var int tybarindex            = na
var string signaldir   = na
var string signaldir2   = na
var string signaldir3   = na
var bool ptopb = na
var bool p2topb = na
var bool p3topb = na
var bool ptop2b = na    
var bool p2top2b = na    
var bool p3top2b = na 
var bool pbtm2b = na
var bool p2btm2b = na
var bool p3btm2b = na
var bool pfib1b = na        
var bool p2fib1b = na        
var bool p3fib1b = na
var bool pfib3b = na        
var bool p2fib3b = na        
var bool p3fib3b = na 
var bool pfib4b = na        
var bool p2fib4b = na        
var bool p3fib4b = na 
var bool pfib5b = na        
var bool p2fib5b = na        
var bool p3fib5b = na 
var bool pfib6b = na        
var bool p2fib6b = na        
var bool p3fib6b = na 
var bool pfib7b = na        
var bool p2fib7b = na        
var bool p3fib7b = na  
var bool pfib8b = na        
var bool p2fib8b = na        
var bool p3fib8b = na 
var bool ptop2bb = na        
var bool p2top2bb = na        
var bool p3top2bb = na 
var bool pbtm2bb = na        
var bool p2btm2bb = na        
var bool p3btm2bb = na 
var bool pfib1bb = na        
var bool p2fib1bb = na        
var bool p3fib1bb = na
var bool pfib2b = na        
var bool p2fib2b = na        
var bool p3fib2b = na 
var bool pfib9b = na        
var bool p2fib9b = na        
var bool p3fib9b = na
var bool pfib10b = na        
var bool p2fib10b = na        
var bool p3fib10b = na
var bool pfib11b = na        
var bool p2fib11b = na        
var bool p3fib11b = na
var bool pfib12b = na        
var bool p2fib12b = na        
var bool p3fib12b = na 
var bool pfib13b = na        
var bool p2fib13b = na        
var bool p3fib13b = na
var bool pbottomb = na
var bool p2bottomb = na
var bool p3bottomb = na
peakcount = 0
nydayopen = request.security(syminfo.tickerid,"D", open)
if sessiontosession 
    array1off := InSession("1825-1830","GMT-5")
    array2off := InSession("0925-0930","GMT-5")
    array3off := InSession("0255-0300","GMT-5") 
else
    array1off  := InSession("0925-0930" , "GMT-5")
    array2off  := InSession("0255-0300" , "GMT-5")
    array3off  := InSession("1825-1830" , "GMT-5")

if not sessiontosession 
    if arraysess
        array1 := true
    if arraysess2 
        array2 := true
    if arraysess3 
        array3 := true
    peakcount := 192
    sesslength := "FS"

if sessiontosession 
    if arraysess 
        array1 := true
    if arraysess2 
        array2 := true
    if arraysess3 
        array3 := true
    peakcount := 96
    sesslength := "S2S"
//} 
//{ Get HLOC for the previous 12 candles on each candle
top                     = ta.highest(high,12)
bottom                  = ta.lowest(low,12)
topopen                 = ta.highest(open,12)
topclose                = ta.highest(close,12)
btmopen                 = ta.lowest(open,12)
btmclose                = ta.lowest(close,12)
dayweek                 = dayofweek
//}
//{ turn numerical dayofweek into text for labels etc
if dayweek == 1 
    weekday := "Sunday"
else if dayweek == 2
    weekday :=  "Monday"
else if dayweek == 3
    weekday := "Tuesday"
else if dayweek == 4
    weekday :=  "Wednesday"
else if dayweek == 5
    weekday := "Thursday"
else if dayweek == 6
    weekday :=  "Friday"
else if dayweek == 7
    weekday := "Saturday"
//}
//{ Set date range automatically or via manual input in settings menu
if timeish == false 
    if (end2 >= time and start2 <= time)
        indate := true
    else 
        indate := false
else
    na
if timeish
    if (end >= time and start <= time)
        indate := true
    else 
        indate := false
else
    na
 //Decide if high open is higher than high close or vice versa and whether low open is lower than low close or vice versa    
if topopen > topclose
    top2  := topopen
else
    top2  := topclose

if btmopen < btmclose
    btm2  := btmopen
else
    btm2  := btmclose

var float ptop = na
var float pbottom = na
var float ptop2 = na
var float pbtm2 = na
var float p2top = na
var float p2bottom = na
var float p2top2 = na
var float p2btm2 = na
var float p3top = na
var float p3bottom = na
var float p3top2 = na
var float p3btm2 = na
//}
//{ Some Logics
toplabelprice := top + boxlabel
bottomlabelprice := bottom - sessionlabel
colorgrad = top-bottom
if arraysess
    array.push(colorgradarray,colorgrad)
    clrmax := array.max(colorgradarray)
    clrmin := array.min(colorgradarray)
if arraysess2
    array.push(colorgradarray,colorgrad)
    clrmax2 := array.max(colorgradarray)
    clrmin2 := array.min(colorgradarray)
if arraysess3
    array.push(colorgradarray,colorgrad)
    clrmax3 := array.max(colorgradarray)
    clrmin3 := array.min(colorgradarray)
       

fib1   := top2 - ((top2 - btm2)* 0.5)
fib2   := btm2 - ((top2 - btm2)* 2.5)
fib3   := top2 + ((top2 - btm2)* 2.5)
fib4   := top2 + ((top2 - btm2)* 0.5)
fib5   := top2 + ((top2 - btm2)* 1)
fib6   := top2 + ((top2 - btm2)* 1.5)
fib7   := top2 + ((top2 - btm2)* 2)
fib8   := top2 + ((top2 - btm2)* 3)
fib9   := btm2 - ((top2 - btm2)* 0.5)
fib10  := btm2 - ((top2 - btm2)* 1)
fib11  := btm2 - ((top2 - btm2)* 1.5)
fib12  := btm2 - ((top2 - btm2)* 2)
fib13  := btm2 - ((top2 - btm2)* 3)
//}
highp := ta.highest(high,peakcount)
lowp := ta.lowest(low,peakcount)

//{
if barstate.isfirst
    array.push(nydayopena,0.0)
    array.push(signaltimea,   0)
    array.push(signaltime2,   0)
    array.push(signaltime3,   0)
    array.push(symbola, "symb")
    array.push(lowpa,0.0)
    array.push(lowpa2,0.0)
    array.push(lowpa3,0.0)
    array.push(highpa,0.0)
    array.push(highpa2,0.0)
    array.push(highpa3,0.0)
    array.push(signaldira,   "secret is cheese")
    array.push(signaldira2,   "secret is cheese")
    array.push(signaldira3,   "secret is cheese")
    array.push(nybarindexa,   0)
    array.push(ldnbarindexa,0)
    array.push(tybarindexa,0)
    array.push(nyopenarray1,nyopen)
    array.push(nyopenarray2,   nyopen2)
    array.push(nyclosearray1,  nyclose)
    array.push(nyclosearray2,  nyclose2)
    array.push(ldnopenarray1,   nyopen)
    array.push(ldnopenarray2,   nyopen2)
    array.push(ldnclosearray1,  nyclose)
    array.push(ldnclosearray2,  nyclose2)
    array.push(tyopenarray1,   nyopen)
    array.push(tyopenarray2,   nyopen2)
    array.push(tyclosearray1,  nyclose)
    array.push(tyclosearray2,  nyclose2)
    array.push(fib1xa,  fib1x)
    array.push(fib1xxa,  fib1xx)
    array.push(fib2xa,  fib2x)
    array.push(fib3xa,  fib3x)
    array.push(fib4xa,  0)
    array.push(fib5xa,  0)
    array.push(fib6xa,  0)
    array.push(fib7xa,  0)
    array.push(fib8xa,  0)
    array.push(fib9xa,  0)
    array.push(fib10xa,  0)
    array.push(fib11xa,  0)
    array.push(fib12xa,  0)
    array.push(fib13xa,  0)
    array.push(topxa,  0)
    array.push(top2xa,  top2x)
    array.push(top2xxa,  0)
    array.push(btm2xa,  0)
    array.push(btm2xxa,  0)
    array.push(bottomxa,  0)
    array.push(fib1xa2,  0)
    array.push(fib1xxa2,  0)
    array.push(fib2xa2,  0)
    array.push(fib3xa2,  0)
    array.push(fib4xa2,  0)
    array.push(fib5xa2,  0)
    array.push(fib6xa2,  0)
    array.push(fib7xa2,  0)
    array.push(fib8xa2,  0)
    array.push(fib9xa2,  0)
    array.push(fib10xa2,  0)
    array.push(fib11xa2,  0)
    array.push(fib12xa2,  0)
    array.push(fib13xa2,  0)
    array.push(topxa2,  0)
    array.push(top2xa2,  0)
    array.push(top2xxa2,  0)
    array.push(btm2xa2,  0)
    array.push(btm2xxa2,  0)
    array.push(bottomxa2,  0)
    array.push(fib1xa3,  0)
    array.push(fib1xxa3,  0)
    array.push(fib2xa3,  0)
    array.push(fib3xa3,  0)
    array.push(fib4xa3,  0)
    array.push(fib5xa3,  0)
    array.push(fib6xa3,  0)
    array.push(fib7xa3,  0)
    array.push(fib8xa3,  0)
    array.push(fib9xa3,  0)
    array.push(fib10xa3,  0)
    array.push(fib11xa3,  0)
    array.push(fib12xa3,  0)
    array.push(fib13xa3,  0)
    array.push(topxa3,  0)
    array.push(top2xa3,  0)
    array.push(top2xxa3,  0)
    array.push(btm2xa3,  0)
    array.push(btm2xxa3,  0)
    array.push(bottomxa3,  0)
    array.push(fib1a,  fib1b)
    array.push(fib1aa,  false)
    array.push(fib2a,  false)
    array.push(fib3a,  false)
    array.push(fib4a,  false)
    array.push(fib5a,  false)
    array.push(fib6a,  false)
    array.push(fib7a,  false)
    array.push(fib8a,  false)
    array.push(fib9a,  false)
    array.push(fib10a, false)
    array.push(fib11a, false)
    array.push(fib12a, false)
    array.push(fib13a, false)
    array.push(topa, false)
    array.push(top2a, false)
    array.push(top2aa, false)
    array.push(bottoma, false)
    array.push(btm2a, false)
    array.push(btm2aa, false)
    array.push(fib1a2,  false)
    array.push(fib1aa2,  false)
    array.push(fib2a2,  false)
    array.push(fib3a2,  false)
    array.push(fib4a2,  false)
    array.push(fib5a2,  false)
    array.push(fib6a2,  false)
    array.push(fib7a2,  false)
    array.push(fib8a2,  false)
    array.push(fib9a2,  false)
    array.push(fib10a2, false)
    array.push(fib11a2, false)
    array.push(fib12a2, false)
    array.push(fib13a2, false)
    array.push(topa2, false)
    array.push(top2a2, false)
    array.push(top2aa2, false)
    array.push(bottoma2, false)
    array.push(btm2a2, false)
    array.push(btm2aa2, false)
    array.push(fib1a3,  false)
    array.push(fib1aa3,  false)
    array.push(fib2a3,  false)
    array.push(fib3a3,  false)
    array.push(fib4a3,  false)
    array.push(fib5a3,  false)
    array.push(fib6a3,  false)
    array.push(fib7a3,  false)
    array.push(fib8a3,  false)
    array.push(fib9a3,  false)
    array.push(fib10a3, false)
    array.push(fib11a3, false)
    array.push(fib12a3, false)
    array.push(fib13a3, false)
    array.push(topa3, false)
    array.push(top2a3, false)
    array.push(top2aa3, false)
    array.push(bottoma3, false)
    array.push(btm2a3, false)
    array.push(btm2aa3, false)
    array.push(dates     , time)
    array.push(sessionID , NYID)
    array.push(ptopz      , top )
    array.push(pbottomz   , bottom)
    array.push(ptop2z     , top2)
    array.push(pbtm2z     , btm2)
    array.push(topz      , top )
    array.push(bottomz   , bottom)
    array.push(top2z     , top2)
    array.push(btm2z     , btm2)
    array.push(fib1z, 0.0)
    array.push(fib2z, 0.0)
    array.push(fib3z, 0.0)
    array.push(fib4z, 0.0)
    array.push(fib5z, 0.0)
    array.push(fib6z, 0.0)
    array.push(fib7z, 0.0)
    array.push(fib8z, 0.0)
    array.push(fib9z, 0.0)
    array.push(fib10z, 0.0)
    array.push(fib11z, 0.0)
    array.push(fib12z, 0.0)
    array.push(fib13z, 0.0)
    array.push(t2opz      , top )
    array.push(b2ottomz   , bottom)
    array.push(t2op2z     , top2)
    array.push(b2tm2z     , btm2)
    array.push(f2ib1z, 0.0)
    array.push(f2ib2z, 0.0)
    array.push(f2ib3z, 0.0)
    array.push(f2ib4z, 0.0)
    array.push(f2ib5z, 0.0)
    array.push(f2ib6z, 0.0)
    array.push(f2ib7z, 0.0)
    array.push(f2ib8z, 0.0)
    array.push(f2ib9z, 0.0)
    array.push(f2ib10z, 0.0)
    array.push(f2ib11z, 0.0)
    array.push(f2ib12z, 0.0)
    array.push(f2ib13z, 0.0)
    array.push(t3opz      , top )
    array.push(b3ottomz   , bottom)
    array.push(t3op2z     , top2)
    array.push(b3tm2z     , btm2)
    array.push(f3ib1z, 0.0)
    array.push(f3ib2z, 0.0)
    array.push(f3ib3z, 0.0)
    array.push(f3ib4z, 0.0)
    array.push(f3ib5z, 0.0)
    array.push(f3ib6z, 0.0)
    array.push(f3ib7z, 0.0)
    array.push(f3ib8z, 0.0)
    array.push(f3ib9z, 0.0)
    array.push(f3ib10z, 0.0)
    array.push(f3ib11z, 0.0)
    array.push(f3ib12z, 0.0)
    array.push(f3ib13z, 0.0)
    array.push(dates2     , time)
    array.push(sessionID2 , NYID)
    array.push(topz2      , top )
    array.push(bottomz2   , bottom)
    array.push(top2z2     , top2)
    array.push(btm2z2     , btm2)
    array.push(p2topz      , top )
    array.push(p2bottomz   , bottom)
    array.push(p2top2z     , top2)
    array.push(p2btm2z     , btm2)
    array.push(fib1z2, 0.0)
    array.push(fib2z2, 0.0)
    array.push(fib3z2, 0.0)
    array.push(fib4z2, 0.0)
    array.push(fib5z2, 0.0)
    array.push(fib6z2, 0.0)
    array.push(fib7z2, 0.0)
    array.push(fib8z2, 0.0)
    array.push(fib9z2, 0.0)
    array.push(fib10z2, 0.0)
    array.push(fib11z2, 0.0)
    array.push(fib12z2, 0.0)
    array.push(fib13z2, 0.0)
    array.push(dates3     , time)
    array.push(sessionID3 , NYID)
    array.push(topz3      , top )
    array.push(bottomz3   , bottom)
    array.push(top2z3     , top2)
    array.push(btm2z3     , btm2)
    array.push(p3topz      , top )
    array.push(p3bottomz   , bottom)
    array.push(p3top2z     , top2)
    array.push(p3btm2z     , btm2)
    array.push(fib1z3, 0.0)
    array.push(fib2z3, 0.0)
    array.push(fib3z3, 0.0)
    array.push(fib4z3, 0.0)
    array.push(fib5z3, 0.0)
    array.push(fib6z3, 0.0)
    array.push(fib7z3, 0.0)
    array.push(fib8z3, 0.0)
    array.push(fib9z3, 0.0)
    array.push(fib10z3, 0.0)
    array.push(fib11z3, 0.0)
    array.push(fib12z3, 0.0)
    array.push(fib13z3, 0.0)
    array.push(sesslengtha, sesslength)
    arrayplus1 := array.size(dates)
    arrayplus2 := array.size(dates2)
    arrayplus3 := array.size(dates3)
    arrayplusz := array.size(topz)
    arrayplusz2 := array.size(t2opz)
    arrayplusz3 := array.size(t3opz)
    

 
    nyopen  := open
    nyopen2 := close 
    nyclose := open
    nyclose2  := close
    
if opensess2 and indate and ldntrue 
    ldnopen  := open
    ldnopen2 := close 
    
if arraysess2 and indate and ldntrue
    ldnclose := open
    ldnclose2  := close
    
if opensess3 and indate and tkotrue 
    tyopen  := open
    tyopen2 := close
 
   
    
if arraysess3 and indate and tkotrue 
    tyclose := open
    tyclose2  := close
    

if not indate
    nycleanarray1 :=  false
    nycleanarray2 :=  false
    ldncleanarray1 :=  false
    ldncleanarray2 :=  false
    tycleanarray1 :=  false
    tycleanarray2 :=  false


if indate
    
    if nysess and nytrue
        boxy  := box.new(bar_index[11], top, bar_index, bottom,bgcolor=color.new(color.from_gradient(colorgrad,clrmin,clrmax,nycolor1,nycolor2),65))
        boxy2 := box.new(bar_index[11], top2, bar_index, btm2, bgcolor=color.new(color.from_gradient(colorgrad,clrmax,clrmin,nycolor1,nycolor2),65))
        box.delete(boxy[1])
        box.delete(boxy2[1])
        if labelson
            label1 := label.new(bar_index,toplabelprice, text = "DR Top: "+ str.tostring(top,format.mintick)+ "\n DR Btm: " +str.tostring(bottom,format.mintick)+ "\n IDR Top: "+str.tostring(top2,format.mintick)+ "\n IDR Btm: "+str.tostring(btm2,format.mintick)+"\n9:30 O:"+str.tostring(open[11],format.mintick)+" C:"+str.tostring(close[11],format.mintick)+"\n10:30 O:"+str.tostring(open,format.mintick)+" C:"+str.tostring(close,format.mintick),
                 yloc = yloc.price ,color=color.new(tycolor2,55), 
                     style=label.style_label_center, textcolor=color.rgb(255, 250, 252, 5), size=size.normal, textalign = text.align_center,text_font_family=font.family_monospace)
            label2 := label.new(bar_index[5.5],bottomlabelprice, text = "Session: NY:\n "+str.tostring(dayofmonth) +"/"+str.tostring(month)+"/"+str.tostring(year)+"\n"+str.tostring(weekday),
                 yloc = yloc.price ,color=color.new(ldncolor2,55), 
                     style=label.style_text_outline, textcolor=color.rgb(248, 248, 248, 5), size=size.normal, textalign = text.align_center,  text_font_family=font.family_monospace)
            label.delete(label1[1])
            label.delete(label2[1])
                 
    
    if london and ldntrue
        boxy3 := box.new(bar_index[11], top, bar_index, bottom, bgcolor=color.new(color.from_gradient(colorgrad,clrmin2,clrmax2,ldncolor1,ldncolor2),65))
        boxy4 := box.new(bar_index[11], top2, bar_index, btm2,  bgcolor=color.new(color.from_gradient(colorgrad,clrmax2,clrmin2,ldncolor1,ldncolor2),65))
        box.delete(boxy3[1])
        box.delete(boxy4[1])
        if labelson
            label3 := label.new(bar_index,toplabelprice, text = "DR Top: "+ str.tostring(top,format.mintick)+ "\n DR Btm: " +str.tostring(bottom,format.mintick)+ "\n IDR Top: "+str.tostring(top2,format.mintick)+ "\n IDR Btm: "+str.tostring(btm2,format.mintick),
                 yloc = yloc.price ,color=color.new(nycolor1,55), 
                     style=label.style_label_center, textcolor=color.rgb(255, 250, 252, 5), size=size.normal, textalign = text.align_center,text_font_family=font.family_monospace)
            label4 := label.new(bar_index[5.5],bottomlabelprice, text = "Session: London:\n "+str.tostring(dayofmonth) +"/"+str.tostring(month)+"/"+str.tostring(year)+"\n"+str.tostring(weekday),
                 yloc = yloc.price ,color=color.new(nycolor2,55),
                     style=label.style_text_outline, textcolor=color.rgb(248, 248, 248, 5), size=size.normal, textalign = text.align_center,  text_font_family=font.family_monospace)
            label.delete(label3[1])
            label.delete(label4[1])

    if tokio and tkotrue
        boxy5 := box.new(bar_index[11], top, bar_index, bottom, bgcolor=color.new(color.from_gradient(colorgrad,clrmin3,clrmax3,tycolor1,tycolor2),65))
        boxy6 := box.new(bar_index[11], top2, bar_index, btm2,   bgcolor=color.new(color.from_gradient(colorgrad,clrmax3,clrmin3,tycolor1,tycolor2),65))
        box.delete(boxy5[1])
        box.delete(boxy6[1])
        if labelson
            label5 := label.new(bar_index,toplabelprice, text = "DR Top: "+ str.tostring(top,format.mintick)+ "\n DR Btm: " +str.tostring(bottom,format.mintick)+ "\n IDR Top: "+str.tostring(top2,format.mintick)+ "\n IDR Btm: "+str.tostring(btm2,format.mintick),
                 yloc = yloc.price ,color=color.new(tycolor1,55), 
                     style=label.style_label_center, textcolor=color.rgb(255, 250, 252, 5), size=size.normal, textalign = text.align_center,text_font_family=font.family_monospace)
            label6 := label.new(bar_index[5.5],bottomlabelprice, text = "Session: Tokio:\n "+str.tostring(dayofmonth) +"/"+str.tostring(month)+"/"+str.tostring(year)+"\n"+str.tostring(weekday),
                 yloc = yloc.price ,color=color.new(ldncolor1,55), 
                     style=label.style_text_outline, textcolor=color.rgb(248, 248, 248, 5), size=size.normal, textalign = text.align_center,  text_font_family=font.family_monospace)
            label.delete(label5[1])
            label.delete(label6[1])

if (arraysess and nytrue or arraysess2 and ldntrue or arraysess3 and tkotrue) and stdlevels and indate
    rightlinex := bar_index + 120  
    usline1 := line.new(bar_index[11],top,rightlinex,top, xloc= xloc.bar_index,color = color.aqua)
    usline2 := line.new(bar_index[11],top2,rightlinex,top2, xloc= xloc.bar_index,color = color.purple)
    usline3 := line.new(bar_index[11],bottom,rightlinex,bottom, xloc= xloc.bar_index,color = color.rgb(184, 169, 35))
    usline4 := line.new(bar_index[11],btm2,rightlinex,btm2, xloc= xloc.bar_index,color = color.green)
    usline5 := line.new(bar_index[11],fib1,rightlinex,fib1, xloc= xloc.bar_index,color = color.rgb(38, 23, 235))
    usline6 := line.new(bar_index[11],fib2,rightlinex,fib2, xloc= xloc.bar_index,color = color.rgb(9, 182, 116))
    usline7 := line.new(bar_index[11],fib3,rightlinex,fib3, xloc= xloc.bar_index,color = color.rgb(189, 119, 235))
    usline8 := line.new(bar_index[11],fib4,rightlinex,fib4, xloc= xloc.bar_index,color = color.rgb(57, 160, 108))
    usline9 := line.new(bar_index[11],fib5,rightlinex,fib5, xloc= xloc.bar_index,color = color.rgb(161, 194, 12))
    usline10 := line.new(bar_index[11],fib6,rightlinex,fib6, xloc= xloc.bar_index,color = color.rgb(235, 108, 23))
    usline11 := line.new(bar_index[11],fib7,rightlinex,fib7, xloc= xloc.bar_index,color = color.rgb(175, 17, 17))
    usline12 := line.new(bar_index[11],fib8,rightlinex,fib8, xloc= xloc.bar_index,color = color.rgb(235, 23, 207))
    usline13 := line.new(bar_index[11],fib9,rightlinex,fib9, xloc= xloc.bar_index,color = color.rgb(131, 174, 209))
    usline14 := line.new(bar_index[11],fib10,rightlinex,fib10, xloc= xloc.bar_index,color = color.rgb(0, 189, 189))
    usline15 := line.new(bar_index[11],fib11,rightlinex,fib11, xloc= xloc.bar_index,color = color.rgb(112, 150, 7))
    usline16 := line.new(bar_index[11],fib12,rightlinex,fib12, xloc= xloc.bar_index,color = color.rgb(182, 146, 49))
    usline17 := line.new(bar_index[11],fib13,rightlinex,fib13, xloc= xloc.bar_index,color = color.rgb(211, 162, 240))
    if fiblabels
        linelabel1 := label.new(bar_index[13],top + 1.5,"DR "+str.tostring(top,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel2 := label.new(bar_index[13],top2 - 1.5,"IDR "+str.tostring(top2,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel3 := label.new(bar_index[13],btm2 + 1.5,"IDR "+str.tostring(btm2,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel4 := label.new(bar_index[13],bottom - 1.5,"DR "+str.tostring(bottom,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel5 := label.new(bar_index[13],fib1 ,"0.5 "     +str.tostring(fib1,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel6 := label.new(bar_index[13],fib2 ,"2.5 "     +str.tostring(fib2,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel7 := label.new(bar_index[13],fib3 ,"2.5 "     +str.tostring(fib3,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel8 := label.new(bar_index[13],fib4 ,"0.5 "     +str.tostring(fib4,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel9 := label.new(bar_index[13],fib5 ,"1 "+     str.tostring(fib5,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel10 := label.new(bar_index[13],fib6,"1.5 "+     str.tostring(fib6,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel11 := label.new(bar_index[13],fib7,"2 "+     str.tostring(fib7,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel12 := label.new(bar_index[13],fib8,"3 "+     str.tostring(fib8,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel13 := label.new(bar_index[13],fib9,"0.5 "+     str.tostring(fib9,format.mintick),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel14 := label.new(bar_index[13],fib10,"1 "+str.tostring(fib10),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel15 := label.new(bar_index[13],fib11 ,"1.5 "+str.tostring(fib11),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel16 := label.new(bar_index[13],fib12 ,"2 "+str.tostring(fib12),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)
        linelabel17 := label.new(bar_index[13],fib13 ,"3 "+str.tostring(fib13),text_font_family = font.family_default ,yloc = yloc.price,color =color.rgb(255, 255, 255),style= label.style_none ,textcolor=color.white,size= size.normal, textalign= text.align_left)


var barznting = 0

//}
if prearray1 and indate and nytrue and startarray
    array.push(dates, date) 
    array.push(sessionID , NYID) 
    array.push(sesslengtha,sesslength) 
    array.push(nybarindexa  ,nybarindex   ) 
    array.push(signaldira  ,signaldir   ) 
    array.push(signaltimea , bartimesignal) 
    array.push(symbola  ,symbol   ) 
    array.push(ptopz  , ptop  ) 
    array.push( pbottomz ,pbottom   ) 
    array.push( ptop2z , ptop2  ) 
    array.push(pbtm2z  , pbtm2  ) 
    array.push(nyopenarray1  , nyopen  ) 
    array.push( nyopenarray2 , nyopen2  ) 
    array.push( nyclosearray1 , nyclose  ) 
    array.push( nyclosearray2 , nyclose2  ) 
    array.push( nydayopena , nydayopen ) 
    array.push(highpa  , highp  ) 
    array.push(lowpa,lowp) 
    array.push(fib1xa,  fib1x)
    array.push(fib1xxa,  fib1xx)
    array.push(fib2xa,  fib2x)
    array.push(fib3xa,  fib3x)
    array.push(fib4xa,  fib4x)
    array.push(fib5xa,  fib5x)
    array.push(fib6xa,  fib6x)
    array.push(fib7xa,  fib7x)
    array.push(fib8xa,  fib8x)
    array.push(fib9xa,  fib9x)
    array.push(fib10xa,  fib10x)
    array.push(fib11xa,  fib11x)
    array.push(fib12xa,  fib12x)
    array.push(fib13xa,  fib13x)
    array.push(topxa,  topx)
    array.push(topa, ptopb)
    array.push(bottomxa,  bottomx)
    array.push(bottoma, pbottomb)
    array.push(top2aa,  ptop2bb)
    array.push(top2xxa, top2xx)
    array.push(top2xa,  top2x)
    array.push(top2a, ptop2b)
    array.push(btm2aa,  pbtm2bb)
    array.push(btm2xxa, btm2xx)
    array.push(btm2xa,  btm2x)
    array.push(btm2a, pbtm2b)
    array.push(fib1a,  pfib1b)
    array.push(fib1aa, pfib1bb)
    array.push(fib2a,  pfib2b)
    array.push(fib3a,  pfib3b)
    array.push(fib4a,  pfib4b)
    array.push(fib5a,  pfib5b)
    array.push(fib6a,  pfib6b)
    array.push(fib7a,  pfib7b)
    array.push(fib8a,  pfib8b)
    array.push(fib9a,  pfib9b)
    array.push(fib10a, pfib10b)
    array.push(fib11a, pfib11b)
    array.push(fib12a, pfib12b)
    array.push(fib13a, pfib13b)
    arrayplus1 := array.size(dates)
    ptopb           := na 
    ptop2b          := na
    ptop2bb         := na
    pbottomb        := na
    pbtm2b          := na
    pbtm2bb         := na
    pfib1b          := na
    pfib1bb         := na
    pfib2b          := na
    pfib3b          := na
    pfib4b          := na
    pfib5b          := na
    pfib6b          := na
    pfib7b          := na
    pfib8b          := na
    pfib9b          := na
    pfib10b         := na
    pfib11b         := na
    pfib12b         := na
    pfib13b         := na
    fib1x           := na
    fib1xx          := na
    fib2x           := na
    fib3x           := na
    fib4x           := na
    fib5x           := na
    fib6x           := na
    fib7x           := na
    fib8x           := na
    fib9x           := na
    fib10x          := na
    fib11x          := na
    fib12x          := na
    fib13x          := na
    top2x           := na
    top2xx          := na
    btm2x           := na
    btm2xx          := na
    topx            := na
    bottomx         := na
if arraysess and indate and nytrue
    date := time
    ptop := top
    pbottom := bottom
    ptop2 := top2
    pbtm2 := btm2
    nybarindex := bar_index
    nyopen  := open[11]
    nyopen2 := close[11] 
    nyclose := open
    nyclose2  := close
    linefill.new(usline12 ,usline7 ,color =    color.new(color.from_gradient(fib8,fib13, fib8,ldncolor1,ldncolor2),75))
    linefill.new(usline7  ,usline11 ,color =    color.new(color.from_gradient(fib3,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline11 ,usline10 ,color =    color.new(color.from_gradient(fib7,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline10 ,usline9 ,color =    color.new(color.from_gradient(fib6,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline9  ,usline8 ,color =    color.new(color.from_gradient(fib5,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline8  ,usline1 ,color =    color.new(color.from_gradient(fib4,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline1  ,usline2 ,color = color.new(color.from_gradient(top,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline2  ,usline5 ,color =  color.new(color.from_gradient(top2,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline5  ,usline4 ,color = color.new(color.from_gradient(fib1,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline4  ,usline3 ,color = color.new(color.from_gradient(bottom,fib13,fib8, ldncolor1,ldncolor2), 75))
    linefill.new(usline3  ,usline13 ,color = color.new(color.from_gradient(btm2,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline13 ,usline14 ,color =     color.new(color.from_gradient(fib9,fib13,fib8, ldncolor1,ldncolor2),75))
    linefill.new(usline14 ,usline15 ,color =   color.new(color.from_gradient(fib10,fib13,fib8,  ldncolor1,ldncolor2),75))
    linefill.new(usline15 ,usline16 ,color =  color.new(color.from_gradient(fib11,fib13,fib8  ,ldncolor1,ldncolor2),75))
    linefill.new(usline16 ,usline6 ,color =   color.new(color.from_gradient(fib12,fib13,fib8,ldncolor1,ldncolor2),75))
    linefill.new(usline6  ,usline17 ,color =   color.new(color.from_gradient(fib2,fib13,fib8,ldncolor1,ldncolor2),75))
    array.push(topz      , top )
    array.push(bottomz   , bottom)
    array.push(top2z     , top2)
    array.push(btm2z     , btm2)
    array.push(fib1z, fib1)
    array.push(fib2z, fib2)
    array.push(fib3z, fib3)
    array.push(fib4z, fib4)
    array.push(fib5z, fib5)
    array.push(fib6z, fib6)
    array.push(fib7z, fib7)
    array.push(fib8z, fib8)
    array.push(fib9z, fib9)
    array.push(fib10z,fib10)
    array.push(fib11z,fib11)
    array.push(fib12z,fib12)
    array.push(fib13z,fib13)
    nycleanarray1 := true
    nycleanarray2 := true
    startarray := true
    array1 := true
    arrayplusz := array.size(topz)



topcross := low[1] < array.get(top2z,arrayplusz - 1) and close > array.get(top2z, arrayplusz - 1)
bottomcross := high[1] > array.get(btm2z,arrayplusz - 1) and close < array.get(btm2z, arrayplusz - 1)

if indate and nytrue
    if array1 and topcross and startarray
        array1 := false
        bartimesignal := bar_index
        t = array.get(top2z,arrayplusz - 1)
        bullsignal = label.new(bar_index,t,"Buy Signal "+str.tostring(bartimesignal), yloc= yloc.price, color = color.lime, style = label.style_cross,textcolor = color.white, size = size.normal)
        top2b := true
        btm2b := true
        fib1b := true
        fib3b := true
        fib4b := true
        fib5b := true
        fib6b := true
        fib7b := true
        fib8b := true
        bottomb := true
        nycleanarray1 := false
        signaldir := "Buy"
        bartimesignal := bar_index
        candlecolorup := true
   
    if array1 and bottomcross and startarray
        array1 := false
        bartimesignal := bar_index
        s = array.get(btm2z,arrayplusz - 1)
        bearsignal = label.new(bar_index,s,"Sell Signal", yloc= yloc.price, color = color.fuchsia, style = label.style_cross,textcolor = color.white, size = size.normal)
        top2bb := true
        btm2bb := true
        fib1bb := true
        fib2b  := true
        fib9b  := true
        fib10b := true
        fib11b := true
        fib12b := true
        fib13b := true
        topb := true
        nycleanarray2 := false
        signaldir := "Sell"
        bartimesignal := bar_index
        candlecolordown := true
    


    bool bottombuycross = na
    bottombuycross := close[1] > array.get(bottomz,arrayplusz - 1) and low < array.get(bottomz, arrayplusz - 1)
    if bottomb and bottombuycross 
        pbottomb := true
        bottomx := bar_index
        bottomxl = label.new(bar_index, low, "Buy Signal Stop X "+str.tostring(bottomx)+" "+str.tostring(bottomb) ,style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        bottomb := false

    
    bool topsellcross = na
    topsellcross := close[1] < array.get(topz,arrayplusz - 1) and high > array.get(topz, arrayplusz - 1)
    if topb and topsellcross
        topx := bar_index
        topxl = label.new(bar_index, low, "Sell Signal Stop "+str.tostring(topx)+" "+str.tostring(topb),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        ptopb := true
        topb   := false
        topsellcross := false
    bool top2buycross = na
    top2buycross := close[1] > array.get(top2z,arrayplusz - 1) and low < array.get(top2z, arrayplusz - 1)


    if top2b and top2buycross
        top2x := bar_index
        ptop2b := true
        idrx = label.new(bar_index, low, "Top IDR Buy X "+str.tostring(top2b)+" "+str.tostring(top2x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        top2b := false
   
    bool btm2buycross = na
    btm2buycross := close[1] > array.get(btm2z,arrayplusz - 1) and low < array.get(btm2z, arrayplusz - 1)


    if btm2b and btm2buycross 
        btm2x := bar_index
        pbtm2b := true
        btm2xl = label.new(bar_index, low, "Btm IDR Buy X "+str.tostring(btm2x)+" "+str.tostring(btm2b),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        btm2b := false
       
    bool fib1buycross = na
    fib1buycross := close[1] > array.get(fib1z,arrayplusz - 1) and low < array.get(fib1z, arrayplusz - 1)
    if fib1b and fib1buycross 
        fib1x := bar_index
        pfib1b := true
        fib1xl = label.new(bar_index, low, "Mid Buy X "+str.tostring(fib1x)+" "+str.tostring(fib1b),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib1b := false



    bool fib3buycross = na
    fib3buycross := close[1] < array.get(fib3z,arrayplusz - 1) and high > array.get(fib3z, arrayplusz - 1)
    if fib3b and fib3buycross 
        fib3x := bar_index
        pfib3b := true
        fib3xl = label.new(bar_index, low, "2.5 Buy X "+str.tostring(fib3x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib3b := false


    bool fib4buycross = na
    fib4buycross := close[1] < array.get(fib4z,arrayplusz - 1) and high > array.get(fib4z, arrayplusz - 1)
    if fib4b and fib4buycross
        fib4x := bar_index
        pfib4b := true
        
        fib4xl = label.new(bar_index, low, "0.5 Buy X "+str.tostring(fib4x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib4b := false

  
    bool fib5buycross = na
    fib5buycross := close[1] < array.get(fib5z,arrayplusz - 1) and high > array.get(fib5z, arrayplusz - 1)
    if fib5b and fib5buycross
        fib5x := bar_index
        pfib5b := true
        
        fib5xl = label.new(bar_index, low, "1 Buy X "+str.tostring(fib5x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib5b := false


    bool fib6buycross = na
    fib6buycross := close[1] < array.get(fib6z,arrayplusz - 1) and high > array.get(fib6z, arrayplusz - 1)
    if fib6b and fib6buycross
        fib6x := bar_index
        pfib6b := true
        
        fib6xl = label.new(bar_index, low, "1.5 Buy X "+str.tostring(fib6x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib6b := false

  
    bool fib7buycross = na
    fib7buycross := close[1] < array.get(fib7z,arrayplusz - 1) and high > array.get(fib7z, arrayplusz - 1)
    if fib7b and fib7buycross
        fib7x := bar_index
        pfib7b := true
        
        fib7xl = label.new(bar_index, low, "2 Buy X "+str.tostring(fib7x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib7b := false

    
    bool fib8buycross = na
    fib8buycross := close[1] < array.get(fib8z,arrayplusz - 1) and high > array.get(fib8z, arrayplusz - 1)
    if fib8b and fib8buycross
        fib8x := bar_index
        pfib8b := true
        
        fib8xl = label.new(bar_index, low, "3 Buy X "+str.tostring(fib8x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib8b := false
   
    bool top2sellcross = na
    top2sellcross := close[1] < array.get(top2z,arrayplusz - 1) and high > array.get(top2z, arrayplusz - 1)
    if top2bb and top2sellcross and startarray
        top2xx := bar_index
        ptop2bb := true
        
        idrxx = label.new(bar_index, low, "Top Sell IDR X "+str.tostring(top2bb)+" "+str.tostring(top2xx),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        top2bb := false
        top2sellcross := false

   
    bool btm2sellcross = na
    btm2sellcross := close[1] < array.get(btm2z,arrayplusz - 1) and high > array.get(btm2z, arrayplusz - 1)
    if btm2bb and btm2sellcross
        btm2xx := bar_index
        pbtm2bb := true
        
        btm2xxl = label.new(bar_index, low, "Btm2 Sell IDR X "+str.tostring(btm2xx),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        btm2bb := false
        //btm2sellcross := false

    
    bool fib1sellcross = na
    fib1sellcross := close[1] < array.get(fib1z,arrayplusz - 1) and high > array.get(fib1z, arrayplusz - 1)
    if fib1bb and fib1sellcross
        fib1xx := bar_index
        pfib1bb := true
        
        fib1xxl = label.new(bar_index, low, "Mid Sell X "+str.tostring(fib1xx),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib1bb := false


    bool fib2sellcross = na
    fib2sellcross := close[1] > array.get(fib2z,arrayplusz - 1) and low < array.get(fib2z, arrayplusz - 1)
    if fib2b and fib2sellcross
        fib2x := bar_index
        pfib2b := true
        
        fib2xl = label.new(bar_index, low, "2.5 Sell cross "+str.tostring(fib2x)+" "+str.tostring(fib2b),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib2b := false

 
    bool fib9sellcross = na
    fib9sellcross := close[1] > array.get(fib9z,arrayplusz - 1) and low < array.get(fib9z, arrayplusz - 1)
    if fib9b and fib9sellcross
        fib9x := bar_index
        pfib9b := true
        
        fib9xl = label.new(bar_index, low, "0.5 Sell X "+str.tostring(fib9x)+" "+str.tostring(fib9b),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib9b := false

 
    bool fib10sellcross = na
    fib10sellcross := close[1] > array.get(fib10z,arrayplusz - 1) and low < array.get(fib10z, arrayplusz - 1)
    if fib10b and fib10sellcross
        fib10x := bar_index
        pfib10b := true
        
        fib10xl = label.new(bar_index, low, "1 Sell X "+str.tostring(fib10x)+" "+str.tostring(fib10b),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib10b := false

 
    bool fib11sellcross = na
    fib11sellcross := close[1] > array.get(fib11z,arrayplusz - 1) and low < array.get(fib11z, arrayplusz - 1)
    if fib11b and fib11sellcross
        fib11x := bar_index
        pfib11b := true
        
        fib11xl = label.new(bar_index, low, "1.5 Sell X "+str.tostring(fib11x)+" "+str.tostring(fib11b),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib11b := false


    bool fib12sellcross = na
    fib12sellcross := close[1] > array.get(fib12z,arrayplusz - 1) and low < array.get(fib12z, arrayplusz - 1)
    if fib12b and fib12sellcross
        fib12x := bar_index
        pfib12b := true
        
        fib12xl = label.new(bar_index, low, "2 Sell X "+str.tostring(fib12x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib12b := false
 
    bool fib13sellcross = na
    fib13sellcross := close[1] > array.get(fib13z,arrayplusz - 1) and low < array.get(fib13z, arrayplusz - 1)
    if fib13b and fib13sellcross
        fib13x := bar_index
        pfib13b := true
        
        fib13xl = label.new(bar_index, low, "3 Sell X "+str.tostring(fib13x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib13b := false


    if array1off
        candlecolorup := false
        candlecolordown := false

    if array1off and top2b//and (indate and nytrue)
        top2b :=false
        ptop2b := false
        top2x := na
        

    if array1off and top2bb// and (indate and nytrue)
        top2bb :=false
        ptop2bb := false
        top2xx := na
        

    if array1off and btm2b
        btm2b :=false
        pbtm2b := false
        btm2x := na
        

    if array1off and btm2bb //and (indate and nytrue)
        btm2bb :=false
        pbtm2bb := false
        btm2xx := na
        
    if array1off and fib1b//and (indate and nytrue)
        fib1b :=false
        pfib1b := false
        fib1x := na
        
    if array1off and  fib1bb
        fib1bb :=false
        pfib1bb := false
        fib1xx := na
        
    if array1off and fib3b
        fib3b :=false
        pfib3b := false
        fib3x := na
        
    if array1off and fib4b
        fib4b :=false
        pfib4b := false
        fib4x := na
        
    if array1off and fib5b
        fib5b :=false
        pfib5b := false
        fib5x := na
        
    if array1off and fib6b
        fib6b :=false
        pfib6b := false
        fib6x := na
        
    if array1off and  fib7b
        fib7b :=false
        pfib7b := false
        fib7x := na
       
    if array1off and  fib8b
        fib8b :=false
        pfib8b := false
        fib8x := na
       
    if array1off and fib2b
        fib2b :=false
        pfib2b := false
        fib2x := na
       
    if array1off and  fib9b
        fib9b :=false
        pfib9b := false
        fib9x := na
        
    if array1off  and fib10b
        fib10b :=false
        pfib10b := false
        fib10x := na
       
    if array1off  and fib11b
        fib11b :=false
        pfib11b := false
        fib11x := na
        
    if array1off  and fib12b
        fib12b :=false
        pfib12b := false
        fib12x := na
       
    if array1off  and fib13b
        fib13b :=false
        pfib13b := false
        fib13x := na
        
    if array1off  and bottomb
        bottomb :=false
        pbottomb := false
        bottomx := na
       
    if array1off and topb 
        topb :=false
        ptopb := false
        topx := na
        
    if nycleanarray1 and array1off
        ptop2b := na
        top2x := na 
        pbtm2b := na
        btm2x := na
        pfib1b := na
        fib1x := na 
        pfib3b := na
        fib3x := na 
        pfib4b := na
        fib4x := na 
        pfib5b := na
        fib5x := na 
        pfib6b := na
        fib6x := na 
        pfib7b := na
        fib7x := na 
        pfib8b := na
        fib8x := na 
        pbottomb := na
        bottomx := na
       
    if nycleanarray2 and array1off
        ptop2bb := na
        top2xx := na 
        pbtm2bb := na
        btm2xx := na
        pfib1bb := na
        fib1xx := na 
        pfib2b := na
        fib2x := na 
        pfib9b := na
        fib9x := na 
        pfib10b := na
        fib10x := na 
        pfib11b := na
        fib11x := na 
        pfib12b := na
        fib12x := na 
        pfib13b := na
        fib13x := na 
        ptopb := na
        topx := na
    if array1off and array1 
        bartimesignal := na
        signaldir := "none"
    if array1off 
        barcount := false


if prearray2 and indate and ldntrue and startarray2
    array.push(dates2, date2) 
    array.push(sessionID2 , NYID) 
    array.push(sesslengtha,sesslength) 
    array.push(ldnbarindexa  ,ldnbarindex   ) 
    array.push(signaldira2  ,signaldir2   ) 
    array.push(signaltime2 , bartimesignal2) 
    array.push(symbola  ,symbol   ) 
    array.push( p2topz  , p2top  ) 
    array.push( p2bottomz ,p2bottom   ) 
    array.push( p2top2z , p2top2  ) 
    array.push( p2btm2z  , p2btm2  ) 
    array.push(ldnopenarray1  ,  ldnopen   ) 
    array.push(ldnopenarray2 ,  ldnopen2  ) 
    array.push(ldnclosearray1 , ldnclose  ) 
    array.push(ldnclosearray2 , ldnclose2  ) 
    array.push( nydayopena , nydayopen ) 
    array.push(highpa2  , highp  ) 
    array.push(lowpa2,    lowp) 
    array.push(fib1xa2,  fib1x2)
    array.push(fib1xxa2,fib1xx2)
    array.push( fib2xa2, fib2x2)
    array.push( fib3xa2, fib3x2)
    array.push( fib4xa2, fib4x2)
    array.push( fib5xa2, fib5x2)
    array.push( fib6xa2, fib6x2)
    array.push( fib7xa2, fib7x2)
    array.push( fib8xa2, fib8x2)
    array.push( fib9xa2, fib9x2)
    array.push(fib10xa2,fib10x2)
    array.push(fib11xa2,fib11x2)
    array.push(fib12xa2,fib12x2)
    array.push(fib13xa2,fib13x2)
    array.push( fib1a2,  fib1b2)
    array.push(fib1aa2, p2fib1bb)
    array.push( fib2a2,  p2fib2b)
    array.push( fib3a2,  p2fib3b)
    array.push( fib4a2,  p2fib4b)
    array.push( fib5a2,  p2fib5b)
    array.push( fib6a2,  p2fib6b)
    array.push( fib7a2,  p2fib7b)
    array.push( fib8a2,  p2fib8b)
    array.push( fib9a2,  p2fib9b)
    array.push(fib10a2, p2fib10b)
    array.push(fib11a2, p2fib11b)
    array.push(fib12a2, p2fib12b)
    array.push(fib13a2, p2fib13b)
    array.push(topxa2,  topx2)
    array.push(topa2, p2topb)
    array.push(bottomxa,  bottomx)
    array.push(bottoma, pbottomb)
    array.push(top2aa,  ptop2bb)
    array.push(top2xxa, top2xx)
    array.push(top2xa2,  top2x2)
    array.push(top2a2, p2top2b)
    array.push(btm2aa2,  p2btm2bb)
    array.push(btm2xxa2, btm2xx2)
    array.push(btm2xa2,  btm2x2)
    array.push(btm2a2,   p2btm2b)
    arrayplus2 := array.size(dates2)
    p2topb           := na 
    p2top2b          := na
    p2top2bb         := na
    p2bottomb        := na
    p2btm2b          := na
    p2btm2bb         := na
    p2fib1b          := na
    p2fib1bb         := na
    p2fib2b          := na
    p2fib3b          := na
    p2fib4b          := na
    p2fib5b          := na
    p2fib6b          := na
    p2fib7b          := na
    p2fib8b          := na
    p2fib9b          := na
    p2fib10b         := na
    p2fib11b         := na
    p2fib12b         := na
    p2fib13b         := na
    fib1x2           := na
    fib1xx2          := na
    fib2x2           := na
    fib3x2           := na
    fib4x2           := na
    fib5x2           := na
    fib6x2           := na
    fib7x2           := na
    fib8x2           := na
    fib9x2           := na
    fib10x2          := na
    fib11x2          := na
    fib12x2          := na
    fib13x2          := na
    top2x2            := na
    top2xx2          := na
    btm2x2            := na
    btm2xx2           := na
    topx2            := na
    bottomx2         := na 

if arraysess2 and indate and ldntrue
    date2 := time
    p2top := top
    p2bottom := bottom
    p2top2 := top2
    p2btm2 := btm2
    ldnbarindex := bar_index
    linefill.new(usline12 ,usline7 ,color =    color.new(color.from_gradient(fib8,fib13, fib8,tycolor1,tycolor2),75))
    linefill.new(usline7  ,usline11 ,color =    color.new(color.from_gradient(fib3,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline11 ,usline10 ,color =    color.new(color.from_gradient(fib7,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline10 ,usline9 ,color =    color.new(color.from_gradient(fib6,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline9  ,usline8 ,color =    color.new(color.from_gradient(fib5,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline8  ,usline1 ,color =    color.new(color.from_gradient(fib4,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline1  ,usline2 ,color = color.new(color.from_gradient(top,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline2  ,usline5 ,color =  color.new(color.from_gradient(top2,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline5  ,usline4 ,color = color.new(color.from_gradient(fib1,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline4  ,usline3 ,color = color.new(color.from_gradient(bottom,fib13,fib8, tycolor1,tycolor2), 75))
    linefill.new(usline3  ,usline13 ,color = color.new(color.from_gradient(btm2,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline13 ,usline14 ,color =     color.new(color.from_gradient(fib9,fib13,fib8, tycolor1,tycolor2),75))
    linefill.new(usline14 ,usline15 ,color =   color.new(color.from_gradient(fib10,fib13,fib8,  tycolor1,tycolor2),75))
    linefill.new(usline15 ,usline16 ,color =  color.new(color.from_gradient(fib11,fib13,fib8  ,tycolor1,tycolor2),75))
    linefill.new(usline16 ,usline6 ,color =   color.new(color.from_gradient(fib12,fib13,fib8,tycolor1,tycolor2),75))
    linefill.new(usline6  ,usline17 ,color =   color.new(color.from_gradient(fib2,fib13,fib8,tycolor1,tycolor2),75))
    array.push(t2opz      , top )
    array.push(b2ottomz   , bottom)
    array.push(t2op2z     , top2)
    array.push(b2tm2z     , btm2)
    array.push(f2ib1z, fib1)
    array.push(f2ib2z, fib2)
    array.push(f2ib3z, fib3)
    array.push(f2ib4z, fib4)
    array.push(f2ib5z, fib5)
    array.push(f2ib6z, fib6)
    array.push(f2ib7z, fib7)
    array.push(f2ib8z, fib8)
    array.push(f2ib9z, fib9)
    array.push(f2ib10z,fib10)
    array.push(f2ib11z,fib11)
    array.push(f2ib12z,fib12)
    array.push(f2ib13z,fib13)
    ldncleanarray1 := true
    ldncleanarray2 := true
    startarray2 := true
    array2 := true
    arrayplusz2 := array.size(t2opz)
    



topcross2 := low[1] < array.get(t2op2z,arrayplusz2 - 1) and close > array.get(t2op2z, arrayplusz2 - 1)
bottomcross2 := high[1] > array.get(b2tm2z,arrayplusz2 - 1) and close < array.get(b2tm2z, arrayplusz2 - 1)

if indate and ldntrue
    if array2 and topcross2 and startarray2
        array2 := false
        bartimesignal2 := bar_index
        g = array.get(t2op2z,arrayplusz2 - 1)
        bullsignal2 = label.new(bar_index,g,"Buy Signal "+str.tostring(bartimesignal), yloc= yloc.price, color = color.lime, style = label.style_cross,textcolor = color.white, size = size.normal)
        top2b2 := true
        btm2b2 := true
        fib1b2 := true
        fib3b2 := true
        fib4b2 := true
        fib5b2 := true
        fib6b2 := true
        fib7b2 := true
        fib8b2 := true
        bottomb2 := true
        ldncleanarray1 := false
        signaldir2 := "Buy"
        bartimesignal2 := bar_index
        candlecolorup2 := true
   
    if array2 and bottomcross2 and startarray2
        array2 := false
        bartimesignal2 := bar_index
        f = array.get(b2tm2z,arrayplusz2 - 1)
        bearsignal2 = label.new(bar_index,f,"Sell Signal", yloc= yloc.price, color = color.fuchsia, style = label.style_cross,textcolor = color.white, size = size.normal)
        top2bb2 := true
        btm2bb2 := true
        fib1bb2 := true
        fib2b2  := true
        fib9b2  := true
        fib10b2 := true
        fib11b2 := true
        fib12b2 := true
        fib13b2 := true
        topb2 := true
        ldncleanarray2 := false
        signaldir2 := "Sell"
        candlecolordown2 := true
    


    bool bottombuycross2 = na
    bottombuycross2 := close[1] > array.get(b2ottomz,arrayplusz2 - 1) and low < array.get(b2ottomz, arrayplusz2 - 1)
    if bottomb2 and bottombuycross2 
        p2bottomb := true
        bottomx2 := bar_index
        bottomxl2 = label.new(bar_index, low, "Buy Signal Stop X "+str.tostring(bottomx)+" "+str.tostring(bottomb) ,style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        bottomb2 := false

    
    bool topsellcross2 = na
    topsellcross2 := close[1] < array.get(t2opz,arrayplusz2 - 1) and high > array.get(t2opz, arrayplusz2 - 1)
    if topb2 and topsellcross2
        topx2 := bar_index
        topxl2 = label.new(bar_index, low, "Sell Signal Stop "+str.tostring(topx2)+" "+str.tostring(topb2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        p2topb := true
        topb2   := false
        topsellcross2 := false
    bool top2buycross2 = na
    top2buycross2 := close[1] > array.get(t2op2z,arrayplusz2 - 1) and low < array.get(t2op2z, arrayplusz2 - 1)


    if top2b2 and top2buycross2
        top2x2 := bar_index
        p2top2b := true
        idrx2 = label.new(bar_index, low, "Top IDR Buy X "+str.tostring(top2b)+" "+str.tostring(top2x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        top2b2 := false
   
    bool btm2buycross2 = na
    btm2buycross2 := close[1] > array.get(b2tm2z,arrayplusz2 - 1) and low < array.get(b2tm2z, arrayplusz2 - 1)


    if btm2b2 and btm2buycross2 
        btm2x2 := bar_index
        p2btm2b := true
        btm2xl2 = label.new(bar_index, low, "Btm IDR Buy X "+str.tostring(btm2x2)+" "+str.tostring(btm2b2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        btm2b2 := false
       
    bool fib1buycross2 = na
    fib1buycross2 := close[1] > array.get(f2ib1z,arrayplusz2 - 1) and low < array.get(f2ib1z, arrayplusz2 - 1)
    if fib1b2 and fib1buycross2 
        fib1x2 := bar_index
        p2fib1b := true
        fib1xl2 = label.new(bar_index, low, "Mid Buy X "+str.tostring(fib1x2)+" "+str.tostring(fib1b2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib1b2 := false



    bool fib3buycross2 = na
    fib3buycross2 := close[1] < array.get(f2ib3z,arrayplusz2 - 1) and high > array.get(f2ib3z, arrayplusz2 - 1)
    if fib3b2 and fib3buycross2 
        fib3x2 := bar_index
        p2fib3b := true
        fib3xl2 = label.new(bar_index, low, "2.5 Buy X "+str.tostring(fib3x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib3b2 := false


    bool fib4buycross2 = na
    fib4buycross2 := close[1] < array.get(f2ib4z,arrayplusz2 - 1) and high > array.get(f2ib4z, arrayplusz2 - 1)
    if fib4b2 and fib4buycross2
        fib4x2 := bar_index
        p2fib4b := true
        
        fib4xl2 = label.new(bar_index, low, "0.5 Buy X "+str.tostring(fib4x2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib4b2 := false

  
    bool fib5buycross2 = na
    fib5buycross2 := close[1] < array.get(f2ib5z,arrayplusz2 - 1) and high > array.get(f2ib5z, arrayplusz2 - 1)
    if fib5b2 and fib5buycross2
        fib5x2 := bar_index
        p2fib5b := true
        
        fib5xl2 = label.new(bar_index, low, "1 Buy X "+str.tostring(fib5x2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib5b2 := false


    bool fib6buycross2 = na
    fib6buycross2 := close[1] < array.get(f2ib6z,arrayplusz2 - 1) and high > array.get(f2ib6z, arrayplusz2 - 1)
    if fib6b2 and fib6buycross2
        fib6x2 := bar_index
        p2fib6b := true
        
        fib6xl2 = label.new(bar_index, low, "1.5 Buy X "+str.tostring(fib6x2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib6b2 := false

  
    bool fib7buycross2 = na
    fib7buycross2 := close[1] < array.get(f2ib7z,arrayplusz2 - 1) and high > array.get(f2ib7z, arrayplusz2 - 1)
    if fib7b2 and fib7buycross2
        fib7x2 := bar_index
        p2fib7b := true
        
        fib7xl2 = label.new(bar_index, low, "2 Buy X "+str.tostring(fib7x2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib7b2 := false

    
    bool fib8buycross2 = na
    fib8buycross2 := close[1] < array.get(f2ib8z,arrayplusz2 - 1) and high > array.get(f2ib8z, arrayplusz2 - 1)
    if fib8b2 and fib8buycross2
        fib8x2 := bar_index
        p2fib8b := true
        
        fib8xl2 = label.new(bar_index, low, "3 Buy X "+str.tostring(fib8x),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib8b2 := false
   
    var bool top2sellcross2 = na
    top2sellcross2 := close[1] < array.get(t2op2z,arrayplusz2 - 1) and high > array.get(t2op2z, arrayplusz2 - 1)
    if top2bb2 and top2sellcross2 and startarray2
        top2xx2 := bar_index
        p2top2bb := true
        
        idrxx2 = label.new(bar_index, low, "Top Sell IDR X "+str.tostring(top2bb2)+" "+str.tostring(top2xx2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        top2bb2 := false
        top2sellcross2 := false

   
    bool btm2sellcross2 = na
    btm2sellcross2 := close[1] < array.get(b2tm2z,arrayplusz2 - 1) and high > array.get(b2tm2z, arrayplusz2 - 1)
    if btm2bb2 and btm2sellcross2
        btm2xx2 := bar_index
        p2btm2bb := true
        
        btm2xxl2 = label.new(bar_index, low, "Btm2 Sell IDR X "+str.tostring(btm2xx2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        btm2bb2 := false
        //btm2sellcross := false

    
    bool fib1sellcross2 = na
    fib1sellcross2 := close[1] < array.get(f2ib1z,arrayplusz2 - 1) and high > array.get(f2ib1z, arrayplusz2 - 1)
    if fib1bb2 and fib1sellcross2
        fib1xx2 := bar_index
        p2fib1bb := true
        
        fib1xxl2 = label.new(bar_index, low, "Mid Sell X "+str.tostring(fib1xx2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib1bb2 := false


    bool fib2sellcross2 = na
    fib2sellcross2 := close[1] > array.get(f2ib2z,arrayplusz2 - 1) and low < array.get(f2ib2z, arrayplusz2 - 1)
    if fib2b2 and fib2sellcross2
        fib2x2 := bar_index
        p2fib2b := true
        
        fib2xl2 = label.new(bar_index, low, "2.5 Sell cross "+str.tostring(fib2x2)+" "+str.tostring(fib2b2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib2b2 := false

 
    bool fib9sellcross2 = na
    fib9sellcross2 := close[1] > array.get(f2ib9z,arrayplusz2 - 1) and low < array.get(f2ib9z, arrayplusz2 - 1)
    if fib9b2 and fib9sellcross2
        fib9x2 := bar_index
        p2fib9b := true
        
        fib9xl2 = label.new(bar_index, low, "0.5 Sell X "+str.tostring(fib9x)+" "+str.tostring(fib9b2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib9b2 := false

 
    bool fib10sellcross2 = na
    fib10sellcross2 := close[1] > array.get(f2ib10z,arrayplusz2 - 1) and low < array.get(f2ib10z, arrayplusz2 - 1)
    if fib10b2 and fib10sellcross2
        fib10x2 := bar_index
        p2fib10b := true
        
        fib10xl2 = label.new(bar_index, low, "1 Sell X "+str.tostring(fib10x2)+" "+str.tostring(fib10b2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib10b2 := false

 
    bool fib11sellcross2 = na
    fib11sellcross2 := close[1] > array.get(f2ib11z,arrayplusz2 - 1) and low < array.get(f2ib11z, arrayplusz2 - 1)
    if fib11b2 and fib11sellcross2
        fib11x2 := bar_index
        p2fib11b := true
        
        fib11xl2 = label.new(bar_index, low, "1.5 Sell X "+str.tostring(fib11x2)+" "+str.tostring(fib11b2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib11b2 := false


    bool fib12sellcross2 = na
    fib12sellcross2 := close[1] > array.get(f2ib12z,arrayplusz2 - 1) and low < array.get(f2ib12z, arrayplusz2 - 1)
    if fib12b2 and fib12sellcross2
        fib12x2 := bar_index
        p2fib12b := true
        
        fib12xl2 = label.new(bar_index, low, "2 Sell X "+str.tostring(fib12x2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib12b2 := false
 
    bool fib13sellcross2 = na
    fib13sellcross2 := close[1] > array.get(f2ib13z,arrayplusz2 - 1) and low < array.get(f2ib13z, arrayplusz2 - 1)
    if fib13b2 and fib13sellcross2
        fib13x2 := bar_index
        p2fib13b := true
        
        fib13xl2 = label.new(bar_index, low, "3 Sell X "+str.tostring(fib13x2),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib13b2 := false


    if array2off
        candlecolorup2 := false
        candlecolordown2 := false

    if array2off and top2b2//and (indate and nytrue)
        top2b2 :=false
        p2top2b := false
        top2x2 := na
        

    if array2off and top2bb2// and (indate and nytrue)
        top2bb2 :=false
        p2top2bb := false
        top2xx2 := na
        

    if array2off and btm2b2
        btm2b2 :=false
        p2btm2b := false
        btm2x2 := na
        

    if array2off and btm2bb2 //and (indate and nytrue)
        btm2bb2 :=false
        p2btm2bb := false
        btm2xx2 := na
        
    if array2off and fib1b2//and (indate and nytrue)
        fib1b2 :=false
        p2fib1b := false
        fib1x2 := na
        
    if array2off and  fib1bb2
        fib1bb2 :=false
        p2fib1bb := false
        fib1xx2 := na
        
    if array2off and fib3b2
        fib3b2 :=false
        p2fib3b := false
        fib3x2 := na
        
    if array2off and fib4b2
        fib4b2 :=false
        p2fib4b := false
        fib4x2 := na
        
    if array2off and fib5b2
        fib5b2 :=false
        p2fib5b := false
        fib5x2 := na
        
    if array2off and fib6b2
        fib6b2 :=false
        p2fib6b := false
        fib6x2 := na
        
    if array2off and  fib7b2
        fib7b2 :=false
        p2fib7b := false
        fib7x2 := na
       
    if array2off and  fib8b2
        fib8b2 :=false
        p2fib8b := false
        fib8x2 := na
       
    if array2off and fib2b2
        fib2b2 :=false
        p2fib2b := false
        fib2x2 := na
       
    if array2off and  fib9b2
        fib9b2 :=false
        p2fib9b := false
        fib9x2 := na
        
    if array2off  and fib10b2
        fib10b2 :=false
        p2fib10b := false
        fib10x2 := na
       
    if array2off  and fib11b2
        fib11b2 :=false
        p2fib11b := false
        fib11x2 := na
        
    if array2off  and fib12b2
        fib12b2 :=false
        p2fib12b := false
        fib12x2 := na
       
    if array2off  and fib13b2
        fib13b2 :=false
        p2fib13b := false
        fib13x2 := na
        
    if array2off  and bottomb2
        bottomb2 :=false 
        p2bottomb := false
        bottomx2 := na
       
    if array2off and topb2
        topb2 :=false 
        p2topb := false
        topx2 := na
        
    if ldncleanarray1 and array2off
        p2top2b := na
        top2x2 := na 
        p2btm2b := na
        btm2x2 := na
        p2fib1b := na
        fib1x2 := na 
        p2fib3b := na
        fib3x2 := na 
        p2fib4b := na
        fib4x2 := na 
        p2fib5b := na
        fib5x2 := na 
        p2fib6b := na
        fib6x2 := na 
        p2fib7b := na
        fib7x2 := na 
        p2fib8b := na
        fib8x2 := na 
        p2bottomb := na
        bottomx2 := na
       
    if ldncleanarray2 and array2off
        p2top2bb := na
        top2xx2 := na 
        p2btm2bb := na
        btm2xx2 := na
        p2fib1bb := na
        fib1xx2 := na 
        p2fib2b := na
        fib2x2 := na 
        p2fib9b := na
        fib9x2 := na 
        p2fib10b := na
        fib10x2 := na 
        p2fib11b := na
        fib11x2 := na 
        p2fib12b := na
        fib12x2 := na 
        p2fib13b := na
        fib13x2 := na 
        p2topb := na
        topx2 := na
        
    if array2off and array2 
        bartimesignal2 := na
        signaldir2 := "None" 
    if array2off 
        barcount2 := false

if prearray3 and indate and tkotrue and startarray3
    array.push(dates3, date3) 
    array.push(sessionID3 , NYID) 
    array.push(sesslengtha,sesslength) 
    array.push(ldnbarindexa  ,ldnbarindex   ) 
    array.push(signaldira3  ,signaldir3   ) 
    array.push(signaltime3 , bartimesignal3) 
    array.push(symbola  ,symbol   ) 
    array.push( p3topz  , p3top  ) 
    array.push( p3bottomz ,p3bottom   ) 
    array.push( p3top2z , p3top2  ) 
    array.push( p3btm2z  , p3btm2  ) 
    array.push(ldnopenarray1  ,  ldnopen   ) 
    array.push(ldnopenarray2 ,  ldnopen2  ) 
    array.push(ldnclosearray1 , ldnclose  ) 
    array.push(ldnclosearray2 , ldnclose2  ) 
    array.push( nydayopena , nydayopen ) 
    array.push(highpa3  , highp  ) 
    array.push(lowpa3,    lowp) 
    array.push(fib1xa3,  fib1x3)
    array.push(fib1xxa3,fib1xx3)
    array.push( fib2xa3, fib2x3)
    array.push( fib3xa3, fib3x3)
    array.push( fib4xa3, fib4x3)
    array.push( fib5xa3, fib5x3)
    array.push( fib6xa3, fib6x3)
    array.push( fib7xa3, fib7x3)
    array.push( fib8xa3, fib8x3)
    array.push( fib9xa3, fib9x3)
    array.push(fib10xa3,fib10x3)
    array.push(fib11xa3,fib11x3)
    array.push(fib12xa3,fib12x3)
    array.push(fib13xa3,fib13x3)
    array.push( fib1a3,  fib1b3)
    array.push(fib1aa3, p3fib1bb)
    array.push( fib2a3,  p3fib2b)
    array.push( fib3a3,  p3fib3b)
    array.push( fib4a3,  p3fib4b)
    array.push( fib5a3,  p3fib5b)
    array.push( fib6a3,  p3fib6b)
    array.push( fib7a3,  p3fib7b)
    array.push( fib8a3,  p3fib8b)
    array.push( fib9a3,  p3fib9b)
    array.push(fib10a3, p3fib10b)
    array.push(fib11a3, p3fib11b)
    array.push(fib12a3, p3fib12b)
    array.push(fib13a3, p3fib13b)
    array.push(topxa3,  topx3)
    array.push(topa3, p3topb)
    array.push(bottomxa,  bottomx)
    array.push(bottoma, pbottomb)
    array.push(top2aa,  ptop2bb)
    array.push(top2xxa, top2xx)
    array.push(top2xa3,  top2x3)
    array.push(top2a3, p3top2b)
    array.push(btm2aa3,  p3btm2bb)
    array.push(btm2xxa3, btm2xx3)
    array.push(btm2xa3,  btm2x3)
    array.push(btm2a3,   p3btm2b)
    arrayplus3 := array.size(dates3)
    p3topb           := na 
    p3top2b          := na
    p3top2bb         := na
    p3bottomb        := na
    p3btm2b          := na
    p3btm2bb         := na
    p3fib1b          := na
    p3fib1bb         := na
    p3fib2b          := na
    p3fib3b          := na
    p3fib4b          := na
    p3fib5b          := na
    p3fib6b          := na
    p3fib7b          := na
    p3fib8b          := na
    p3fib9b          := na
    p3fib10b         := na
    p3fib11b         := na
    p3fib12b         := na
    p3fib13b         := na
    fib1x3           := na
    fib1xx3          := na
    fib2x3           := na
    fib3x3           := na
    fib4x3           := na
    fib5x3           := na
    fib6x3           := na
    fib7x3           := na
    fib8x3           := na
    fib9x3           := na
    fib10x3          := na
    fib11x3          := na
    fib12x3          := na
    fib13x3          := na
    top2x3          := na
    top2xx3          := na
    btm2x3          := na
    btm2xx3          := na
    topx3            := na
    bottomx3          := na

if arraysess3 and indate and tkotrue
    date2 := time
    p3top := top
    p3bottom := bottom
    p3top2 := top2
    p3btm2 := btm2
    tybarindex := bar_index
    linefill.new(usline12 ,usline7 ,color =    color.new(color.from_gradient(fib8,fib13, fib8,nycolor1,nycolor2),75))
    linefill.new(usline7  ,usline11 ,color =    color.new(color.from_gradient(fib3,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline11 ,usline10 ,color =    color.new(color.from_gradient(fib7,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline10 ,usline9 ,color =    color.new(color.from_gradient(fib6,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline9  ,usline8 ,color =    color.new(color.from_gradient(fib5,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline8  ,usline1 ,color =    color.new(color.from_gradient(fib4,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline1  ,usline2 ,color = color.new(color.from_gradient(top,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline2  ,usline5 ,color =  color.new(color.from_gradient(top2,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline5  ,usline4 ,color = color.new(color.from_gradient(fib1,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline4  ,usline3 ,color = color.new(color.from_gradient(bottom,fib13,fib8, nycolor1,nycolor2), 75))
    linefill.new(usline3  ,usline13 ,color = color.new(color.from_gradient(btm2,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline13 ,usline14 ,color =     color.new(color.from_gradient(fib9,fib13,fib8, nycolor1,nycolor2),75))
    linefill.new(usline14 ,usline15 ,color =   color.new(color.from_gradient(fib10,fib13,fib8,  nycolor1,nycolor2),75))
    linefill.new(usline15 ,usline16 ,color =  color.new(color.from_gradient(fib11,fib13,fib8  ,nycolor1,nycolor2),75))
    linefill.new(usline16 ,usline6 ,color =   color.new(color.from_gradient(fib12,fib13,fib8,nycolor1,nycolor2),75))
    linefill.new(usline6  ,usline17 ,color =   color.new(color.from_gradient(fib2,fib13,fib8,nycolor1,nycolor2),75))
    array.push(t3opz      , top )
    array.push(b3ottomz   , bottom)
    array.push(t3op2z     , top2)
    array.push(b3tm2z     , btm2)
    array.push(f3ib1z, fib1)
    array.push(f3ib2z, fib2)
    array.push(f3ib3z, fib3)
    array.push(f3ib4z, fib4)
    array.push(f3ib5z, fib5)
    array.push(f3ib6z, fib6)
    array.push(f3ib7z, fib7)
    array.push(f3ib8z, fib8)
    array.push(f3ib9z, fib9)
    array.push(f3ib10z,fib10)
    array.push(f3ib11z,fib11)
    array.push(f3ib12z,fib12)
    array.push(f3ib13z,fib13)
    tycleanarray1 := true
    tycleanarray2 := true
    startarray3 := true
    array3 := true
    arrayplusz3 := array.size(t3opz)

    


topcross3 := low[1] < array.get(t3op2z,arrayplusz3 - 1) and close > array.get(t3op2z, arrayplusz3 - 1)
bottomcross3 := high[1] > array.get(b3tm2z,arrayplusz3 - 1) and close < array.get(b3tm2z, arrayplusz3 - 1)

if indate and tkotrue
    if array3 and topcross3 and startarray3
        array3 := false
        bartimesignal3 := bar_index
        t = array.get(t3op2z,arrayplusz3 - 1)
        bullsignal3 = label.new(bar_index,t,"Buy Signal "+str.tostring(bartimesignal), yloc= yloc.price, color = color.lime, style = label.style_cross,textcolor = color.white, size = size.normal)
        top2b3 := true
        btm2b3 := true
        fib1b3 := true
        fib3b3 := true
        fib4b3 := true
        fib5b3 := true
        fib6b3 := true
        fib7b3 := true
        fib8b3 := true
        bottomb3 := true
        tycleanarray1 := false
        signaldir3 := "Buy"
        bartimesignal3 := bar_index
        candlecolorup3 := true
   
    if array3 and bottomcross3 and startarray3
        array3 := false
        bartimesignal3 := bar_index
        s = array.get(b3tm2z,arrayplusz3 - 1)
        bearsignal3 = label.new(bar_index,s,"Sell Signal", yloc= yloc.price, color = color.fuchsia, style = label.style_cross,textcolor = color.white, size = size.normal)
        top2bb3 := true
        btm2bb3 := true
        fib1bb3 := true
        fib2b3  := true
        fib9b3  := true
        fib10b3 := true
        fib11b3 := true
        fib12b3 := true
        fib13b3 := true
        topb3 := true
        tycleanarray2 := false
        signaldir3 := "Sell"
        bartimesignal3 := bar_index
        candlecolordown3 := true
    


    bool bottombuycross3 = na
    bottombuycross3 := close[1] > array.get(b3ottomz,arrayplusz3 - 1) and low < array.get(b3ottomz, arrayplusz3 - 1)
    if bottomb3 and bottombuycross3 
        p3bottomb := true
        bottomx3 := bar_index
        bottomxl3 = label.new(bar_index, low, "Buy Signal Stop X "+str.tostring(bottomx3)+" "+str.tostring(bottomb3) ,style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        bottomb3 := false

    
    bool topsellcross3 = na
    topsellcross3 := close[1] < array.get(t3opz,arrayplusz3 - 1) and high > array.get(t3opz, arrayplusz3 - 1)
    if topb3 and topsellcross3
        topx3 := bar_index
        topxl = label.new(bar_index, low, "Sell Signal Stop "+str.tostring(topx3)+" "+str.tostring(topb3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        p3topb := true
        topb3   := false
        topsellcross3 := false
    bool top2buycross3 = na
    top2buycross3 := close[1] > array.get(t3op2z,arrayplusz3 - 1) and low < array.get(t3op2z, arrayplusz3 - 1)


    if top2b3 and top2buycross3
        top2x3 := bar_index
        p3top2b := true
        idrx3 = label.new(bar_index, low, "Top IDR Buy X "+str.tostring(top2b3)+" "+str.tostring(top2x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        top2b3 := false
   
    bool btm2buycross3 = na
    btm2buycross3 := close[1] > array.get(b3tm2z,arrayplusz3 - 1) and low < array.get(b3tm2z, arrayplusz3 - 1)


    if btm2b3 and btm2buycross3 
        btm2x3 := bar_index
        p3btm2b := true
        btm2xl3 = label.new(bar_index, low, "Btm IDR Buy X "+str.tostring(btm2x3)+" "+str.tostring(btm2b3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        btm2b3 := false
       
    bool fib1buycross3 = na
    fib1buycross3 := close[1] > array.get(f3ib1z,arrayplusz3 - 1) and low < array.get(f3ib1z, arrayplusz3 - 1)
    if fib1b3 and fib1buycross3 
        fib1x3 := bar_index
        p3fib1b := true
        fib1xl3 = label.new(bar_index, low, "Mid Buy X "+str.tostring(fib1x3)+" "+str.tostring(fib1b3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib1b3 := false



    bool fib3buycross3 = na
    fib3buycross3 := close[1] < array.get(f3ib3z,arrayplusz3 - 1) and high > array.get(f3ib3z, arrayplusz3 - 1)
    if fib3b3 and fib3buycross3 
        fib3x3 := bar_index
        p3fib3b := true
        fib3xl3 = label.new(bar_index, low, "2.5 Buy X "+str.tostring(fib3x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib3b3 := false


    bool fib4buycross3 = na
    fib4buycross3 := close[1] < array.get(f3ib4z,arrayplusz3 - 1) and high > array.get(f3ib4z, arrayplusz3 - 1)
    if fib4b3 and fib4buycross3
        fib4x3 := bar_index
        p3fib4b := true
        
        fib4xl3 = label.new(bar_index, low, "0.5 Buy X "+str.tostring(fib4x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib4b3 := false

  
    bool fib5buycross3 = na
    fib5buycross3 := close[1] < array.get(f3ib5z,arrayplusz3 - 1) and high > array.get(f3ib5z, arrayplusz3 - 1)
    if fib5b3 and fib5buycross3
        fib5x3 := bar_index
        p3fib5b := true
        
        firb5xl = label.new(bar_index, low, "1 Buy X "+str.tostring(fib5x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib5b3 := false


    bool fib6buycross3 = na
    fib6buycross3 := close[1] < array.get(f3ib6z,arrayplusz3 - 1) and high > array.get(f3ib6z, arrayplusz3 - 1)
    if fib6b3 and fib6buycross3
        fib6x3 := bar_index
        p3fib6b := true
        
        fidb6xl = label.new(bar_index, low, "1.5 Buy X "+str.tostring(fib6x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib6b3 := false

  
    bool fib7buycross3 = na
    fib7buycross3 := close[1] < array.get(f3ib7z,arrayplusz3 - 1) and high > array.get(f3ib7z, arrayplusz3 - 1)
    if fib7b3 and fib7buycross3
        fib7x3 := bar_index
        p3fib7b := true
        
        fidb7xl = label.new(bar_index, low, "2 Buy X "+str.tostring(fib7x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib7b3 := false

    
    bool fib8buycross3 = na
    fib8buycross3 := close[1] < array.get(f3ib8z,arrayplusz3 - 1) and high > array.get(f3ib8z, arrayplusz3 - 1)
    if fib8b3 and fib8buycross3
        fib8x3 := bar_index
        p3fib8b := true
        
        fib8xl = label.new(bar_index, low, "3 Buy X "+str.tostring(fib8x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib8b3 := false
   
    var bool top2sellcross3 = na
    top2sellcross3 := close[1] < array.get(t3op2z,arrayplusz3 - 1) and high > array.get(t3op2z, arrayplusz3 - 1)
    if top2bb3 and top2sellcross3 and startarray
        top2xx3 := bar_index
        p3top2bb := true
        
        idsrxx = label.new(bar_index, low, "Top Sell IDR X "+str.tostring(top2bb3)+" "+str.tostring(top2xx3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        top2bb3 := false
        top2sellcross3 := false

   
    bool btm2sellcross3 = na
    btm2sellcross3 := close[1] < array.get(b3tm2z,arrayplusz3 - 1) and high > array.get(b3tm2z, arrayplusz3 - 1)
    if btm2bb3 and btm2sellcross3
        btm2xx3 := bar_index
        p3btm2bb := true
        
        btm2xxlfr = label.new(bar_index, low, "Btm2 Sell IDR X "+str.tostring(btm2xx3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        btm2bb3 := false
        //btm2sellcross := false

    
    bool fib1sellcross3 = na
    fib1sellcross3 := close[1] < array.get(f3ib1z,arrayplusz3 - 1) and high > array.get(f3ib1z, arrayplusz3 - 1)
    if fib1bb3 and fib1sellcross3
        fib1xx3 := bar_index
        p3fib1bb := true
        
        fidb1xxl = label.new(bar_index, low, "Mid Sell X "+str.tostring(fib1xx3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib1bb3 := false


    bool fib2sellcross3 = na
    fib2sellcross3 := close[1] > array.get(f3ib2z,arrayplusz3 - 1) and low < array.get(f3ib2z, arrayplusz3 - 1)
    if fib2b3 and fib2sellcross3
        fib2x3 := bar_index
        p3fib2b := true
        
        fisb2xl = label.new(bar_index, low, "2.5 Sell cross "+str.tostring(fib2x3)+" "+str.tostring(fib2b3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib2b3 := false

 
    bool fib9sellcross3 = na
    fib9sellcross3 := close[1] > array.get(f3ib9z,arrayplusz3 - 1) and low < array.get(f3ib9z, arrayplusz3 - 1)
    if fib9b3 and fib9sellcross3
        fib9x3 := bar_index
        p3fib9b := true
        
        ficb9xl = label.new(bar_index, low, "0.5 Sell X "+str.tostring(fib9x3)+" "+str.tostring(fib9b3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib9b3 := false

 
    bool fib10sellcross3 = na
    fib10sellcross3 := close[1] > array.get(f3ib10z,arrayplusz3 - 1) and low < array.get(f3ib10z, arrayplusz3 - 1)
    if fib10b3 and fib10sellcross3
        fib10x3 := bar_index
        p3fib10b := true
        
        fifb10xl = label.new(bar_index, low, "1 Sell X "+str.tostring(fib10x3)+" "+str.tostring(fib10b3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib10b3 := false

 
    bool fib11sellcross3 = na
    fib11sellcross3 := close[1] > array.get(f3ib11z,arrayplusz3 - 1) and low < array.get(f3ib11z, arrayplusz3 - 1)
    if fib11b3 and fib11sellcross3
        fib11x3 := bar_index
        p3fib11b := true
        
        fifb11xl = label.new(bar_index, low, "1.5 Sell X "+str.tostring(fib11x3)+" "+str.tostring(fib11b3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib11b3 := false


    bool fib12sellcross3 = na
    fib12sellcross3 := close[1] > array.get(f3ib12z,arrayplusz3 - 1) and low < array.get(f3ib12z, arrayplusz3 - 1)
    if fib12b3 and fib12sellcross3
        fib12x3 := bar_index
        p3fib12b := true
        
        fidb12xl = label.new(bar_index, low, "2 Sell X "+str.tostring(fib12x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib12b3 := false
 
    bool fib13sellcross3 = na
    fib13sellcross3 := close[1] > array.get(f3ib13z,arrayplusz3 - 1) and low < array.get(f3ib13z, arrayplusz3 - 1)
    if fib13b3 and fib13sellcross3
        fib13x3 := bar_index
        p3fib13b := true
        
        fib13xl = label.new(bar_index, low, "3 Sell X "+str.tostring(fib13x3),style = label.style_cross, color = tycolor2,textcolor = chart.fg_color)
        fib13b3 := false


    if array3off
        candlecolorup3 := false
        candlecolordown3 := false

    if array3off and top2b3//and (indate and tytrue)
        top2b3 :=false
        p3top2b := false
        top2x3 := na
        

    if array3off and top2bb3
        top2bb3 := false// and (indate and tytrue)
        p3top2bb := false
        top2xx3 := na
        

    if array3off and btm2b3
        btm2b3 := false
        p3btm2b := false
        btm2x3 := na
        

    if array3off and btm2bb3 //and (indate and tytrue)
        btm2bb3 := false
        p3btm2bb := false
        btm2xx3 := na
        
    if array3off and fib1b3//and (indate and tytrue)
        fib1b3 := false
        p3fib1b := false
        fib1x3 := na
        
    if array3off and  fib1bb3
        fib1bb3 := false
        p3fib1bb := false
        fib1xx3 := na
        
    if array3off and fib3b3
        fib3b3 := false
        p3fib3b := false
        fib3x3 := na
        
    if array3off and fib4b3
        fib4b3 := false
        p3fib4b := false
        fib4x3 := na
        
    if array3off and fib5b3
        fib5b3 := false
        p3fib5b := false
        fib5x3 := na
        
    if array3off and fib6b3
        fib6b3 := false
        p3fib6b := false
        fib6x3 := na
        
    if array3off and  fib7b3
        fib7b3 := false
        p3fib7b := false
        fib7x3 := na
       
    if array3off and  fib8b3
        fib8b3 := false
        p3fib8b := false
        fib8x3 := na
       
    if array3off and fib2b3
        fib2b3 := false
        p3fib2b := false
        fib2x3 := na
       
    if array3off and  fib9b3
        fib9b3 := false
        p3fib9b := false
        fib9x3 := na
        
    if array3off  and fib10b3
        fib10b3 := false
        p3fib10b := false
        fib10x3 := na
       
    if array3off  and fib11b3
        fib11b3 := false
        p3fib11b := false
        fib11x3 := na
        
    if array3off  and fib12b3
        fib12b3 := false
        p3fib12b := false
        fib12x3 := na
       
    if array3off  and fib13b3
        fib13b3 := false
        p3fib13b := false
        fib13x3 := na
        
    if array3off  and bottomb3
        bottomb3 := false
        p3bottomb := false
        bottomx3 := na
       
    if array3off and topb3 
        topb3 := false
        p3topb := false
        topx3 := na
        
    if tycleanarray1 and array3off
        p3top2b := na
        top2x3 := na 
        p3btm2b := na
        btm2x3 := na
        p3fib1b := na
        fib1x3 := na 
        p3fib3b := na
        fib3x3 := na 
        p3fib4b := na
        fib4x3 := na 
        p3fib5b := na
        fib5x3 := na 
        p3fib6b := na
        fib6x3 := na 
        p3fib7b := na
        fib7x3 := na 
        p3fib8b := na
        fib8x3 := na 
        p3bottomb := na
        bottomx3 := na
       
    if tycleanarray2 and array3off
        p3top2bb := na
        top2xx3 := na 
        p3btm2bb := na
        btm2xx3 := na
        p3fib1bb := na
        fib1xx3 := na 
        p3fib2b := na
        fib2x3 := na 
        p3fib9b := na
        fib9x3 := na 
        p3fib10b := na
        fib10x3 := na 
        p3fib11b := na
        fib11x3 := na 
        p3fib12b := na
        fib12x3 := na 
        p3fib13b := na
        fib13x3 := na 
        p3topb := na
        topx3 := na
    if array3off and array3 
        bartimesignal3 := na
        signaldir3 := "None"
    if array3off 
        barcount3 := false

//{ ipda
var  dayarrayhi        = array.new_float()
var  dayarraylo        = array.new_float()
var  dayarray_offsethi = array.new_float()
var  dayarray_offsetlo = array.new_float()
var int daycount       = 0 

hilo_high              = request.security(syminfo.tickerid, "D", ta.highest(high,20))
hilo_low               = request.security(syminfo.tickerid, "D", ta.lowest(low,20))
hilo_high59            = request.security(syminfo.tickerid, "D", ta.highest(high,59))
hilo_low59             = request.security(syminfo.tickerid, "D", ta.lowest(low,59))
hilo_offsethi          = request.security(syminfo.tickerid, "D", ta.highestbars (high,20))
hilo_offsetlo          = request.security(syminfo.tickerid, "D", ta.lowestbars (low,20))
hilo_offsethi59        = request.security(syminfo.tickerid, "D", ta.highestbars (high,59))
hilo_offsetlo59        = request.security(syminfo.tickerid, "D", ta.lowestbars (low,59))
float hilo_44_hi       = na
float hilo_44_lo       = na
float hilo_44_offsethi = na
float hilo_44_offsetlo = na
float hilo_22_hi       = na
float hilo_22_lo       = na
float hilo_22_offsethi = na
float hilo_22_offsetlo = na
float hilo_68_hi       = na
float hilo_68_lo       = na
float hilo_68_offsethi = na
float hilo_68_offsetlo = na
float ipda             = na
float offset           = na
colorfg = chart.fg_color
//}
if  time == time("", "0000-0005", "GMT-5")
    daycount += 1
    array.push(dayarrayhi, hilo_high)
    array.push(dayarraylo, hilo_low)
    array.push(dayarray_offsethi, hilo_offsethi)
    array.push(dayarray_offsetlo, hilo_offsetlo)

if barstate.islastconfirmedhistory and ipdaon
    hilo_22_hi       := array.get(dayarrayhi, daycount - 1)
    hilo_22_lo       := array.get(dayarraylo, daycount - 1)
    hilo_22_offsethi := array.get(dayarray_offsethi, daycount - 1)
    hilo_22_offsetlo := array.get(dayarray_offsetlo, daycount - 1)
    hilo_22_offsethi := hilo_22_offsethi - 1
    hilo_22_offsetlo := hilo_22_offsetlo - 1
    high22_line       = line.new(bar_index,hilo_22_hi,bar_index[1],hilo_22_hi,xloc.bar_index,extend = extend.both,color = color.new(color.red,30), width = 2)
    if labelson
        high22_label      = label.new(last_bar_index + 50 ,hilo_22_hi, "20 day High\n"+str.tostring(hilo_22_offsethi)+" Days Since High\n"+str.tostring(hilo_22_hi,format.mintick),color = color.new(color.red,50),textcolor = color.white, size = size.small)
    low22_line        = line.new(bar_index,hilo_22_lo,bar_index[1],hilo_22_lo,xloc.bar_index,extend = extend.both,color = color.new(color.blue,30), width = 2)
    if labelson
        low22_label       = label.new(last_bar_index + 50 ,hilo_22_lo, "20 day Low\n"+str.tostring(hilo_22_offsetlo)+" Days Since Low\n"+str.tostring(hilo_22_lo,format.mintick),color = color.new(color.blue,50),textcolor = color.white, size = size.small)
    hilo_44_hi       := array.get(dayarrayhi, daycount - 21)
    hilo_44_lo       := array.get(dayarraylo, daycount - 21)
    hilo_44_offsethi := array.get(dayarray_offsethi, daycount - 21)
    hilo_44_offsetlo := array.get(dayarray_offsetlo, daycount - 21)
    
    hilo_44_offsethi := hilo_44_offsethi - 21
    hilo_44_offsetlo := hilo_44_offsetlo - 21
    high44_line       = line.new(bar_index,hilo_44_hi,bar_index[1],hilo_44_hi,xloc.bar_index,extend = extend.both,color = color.new(color.red,30), width = 2)
    if labelson
        high44_label      = label.new(last_bar_index + 50 ,hilo_44_hi, "40 day High\n"+str.tostring(hilo_44_offsethi)+" Days Since High\n"+str.tostring(hilo_44_hi,format.mintick),color = color.new(color.red,50),textcolor = color.white, size = size.small)
    low44_line        = line.new(bar_index,hilo_44_lo,bar_index[1],hilo_44_lo,xloc.bar_index,extend = extend.both,color = color.new(color.blue,30), width = 2)
    if labelson
        low44_label       = label.new(last_bar_index + 50 ,hilo_44_lo, "40 day Low\n"+str.tostring(hilo_44_offsetlo)+" Days Since Low\n"+str.tostring(hilo_44_lo,format.mintick),color = color.new(color.blue,50),textcolor = color.white, size = size.small)
    hilo_68_hi       := array.get(dayarrayhi, daycount - 40)
    hilo_68_lo       := array.get(dayarraylo, daycount - 40)
    hilo_68_offsethi := array.get(dayarray_offsethi, daycount - 40)
    hilo_68_offsetlo := array.get(dayarray_offsetlo, daycount - 40)
    hilo_68_offsethi := hilo_68_offsethi - 40
    hilo_68_offsetlo := hilo_68_offsetlo - 40
    high68_line       = line.new(bar_index,hilo_68_hi,bar_index[1],hilo_68_hi,xloc.bar_index,extend = extend.both,color = color.new(color.red,30), width = 2)
    if labelson
        high68_label      = label.new(last_bar_index + 50 ,hilo_68_hi, "59 day High\n"+str.tostring(hilo_68_offsethi)+" Days Since High\n"+str.tostring(hilo_68_hi,format.mintick),color = color.new(color.red,50),textcolor = color.white, size = size.small)
    low68_line        = line.new(bar_index,hilo_68_lo,bar_index[1],hilo_68_lo,xloc.bar_index,extend = extend.both,color = color.new(color.blue,30), width = 2)
    if labelson
        low68_label       = label.new(last_bar_index + 50 ,hilo_68_lo, "59 day Low\n"+str.tostring(hilo_68_offsetlo)+" Days Since Low\n"+str.tostring(hilo_68_lo,format.mintick),color = color.new(color.blue,50),textcolor = color.white, size = size.small)
    if (hilo_offsethi59 >= hilo_offsetlo59)
        ipda := hilo_high59
        offset := hilo_offsethi59
        ipdalinehi = line.new(bar_index[1], ipda, last_bar_index, ipda, extend = extend.both, color = color.new(color.lime,50),width = 5)
    else if hilo_offsetlo59 >= hilo_offsethi59
        ipda := hilo_low59
        offset := hilo_offsetlo59
        ipdalinelo = line.new(bar_index[1], ipda, last_bar_index, ipda, extend = extend.both, color = color.new(#0bf303, 50),width = 5)
    ipdalabel = label.new(last_bar_index + 125,ipda, text = "Estimated: "+str.tostring(offset)+" Days Since Quarterly Shift\nEstimated: "+str.tostring(60 + offset)+" Days to next Quarterly Shift",color= colorfg ,style = label.style_label_lower_left,textcolor = chart.bg_color)

down = open - (open - close)
up = close - (close  - open)

barcolor(colorcandles and candlecolorup and (close < open) ? color.from_gradient(down, array.get(fib11z, arrayplus1 - 1)  ,  array.get(fib6z, arrayplus1 - 1),tycolor2, nycolor2) : na)
barcolor(colorcandles and candlecolorup and (open < close) ? color.from_gradient(up,array.get(fib11z, arrayplus1 - 1),array.get(fib6z, arrayplus1 - 1),tycolor1,ldncolor2) : na)
barcolor(colorcandles and candlecolordown and (close < open) ? color.from_gradient(down, array.get(fib11z, arrayplus1 - 1)  ,  array.get(fib6z, arrayplus1 - 1),ldncolor1,nycolor1 ) : na)
barcolor(colorcandles and candlecolordown and (open < close) ? color.from_gradient(up,array.get(fib11z, arrayplus1 - 1),array.get(fib6z, arrayplus1 - 1),nycolor2,ldncolor2) : na)
barcolor(colorcandles and candlecolorup2 and (close < open) ? color.from_gradient(down, array.get(fib11z, arrayplus2 - 1)  ,  array.get(fib6z, arrayplus2 - 1),tycolor1, nycolor1) : na)
barcolor(colorcandles and candlecolorup2 and (open < close) ? color.from_gradient(up,array.get(fib11z, arrayplus2 - 1),array.get(fib6z, arrayplus2 - 1),nycolor2, ldncolor2) : na)
barcolor(colorcandles and candlecolordown2 and (close < open) ? color.from_gradient(down, array.get(fib11z, arrayplus2 - 1)  ,  array.get(fib6z, arrayplus2 - 1),ldncolor1,nycolor1 ) : na)
barcolor(colorcandles and candlecolordown2 and (open < close) ? color.from_gradient(up,array.get(fib11z, arrayplus2 - 1),array.get(fib6z, arrayplus2 - 1),nycolor2,tycolor1) : na)
barcolor(colorcandles and candlecolorup3 and (close < open) ? color.from_gradient(down, array.get(fib11z, arrayplus3 - 1)  ,  array.get(fib6z, arrayplus3 - 1),ldncolor2, ldncolor1) : na)
barcolor(colorcandles and candlecolorup3 and (open < close) ? color.from_gradient(up,array.get(fib11z, arrayplus3 - 1),array.get(fib6z, arrayplus3 - 1),tycolor1,nycolor2) : na)
barcolor(colorcandles and candlecolordown3 and (close < open) ? color.from_gradient(down, array.get(fib11z, arrayplus3 - 1)  ,  array.get(fib6z, arrayplus3 - 1),ldncolor2,tycolor1 ) : na)
barcolor(colorcandles and candlecolordown3 and (open < close) ? color.from_gradient(up,array.get(fib11z, arrayplus3 - 1),array.get(fib6z, arrayplus3 - 1),ldncolor1,tycolor2) : na)
//signaldcolorcandles and ir highp lowp 2 3 i3
//NY ALERT    
if barstate.islast and dataalert and startarray ///
    alert_text = "Date,sess,symb,DR T,DR B,IDR T,IDR B,sessOO,sessOC,sessCO,sessCC,dayopen,nyC barNo,sigDir,sigbar,highp,lowp,idrbuy,idrbX,midbuy,midbuyx,idrbtmb,idrbtmbX,0.5b,0.5bX,1b,1bX,1.5b,1.5bX,2b,2X,2.5b,2.5X,3b,3bX,BStop,BStopX,idrS,idrSX,midsell,midsellx,idrtopS,idrtopsX,0.5s,0.5sX,1s,1sX,1.5S,1.5sx,2s,2sx,2.5s,2.5sx,3s,3sx,selstop,selstopX;\n"
    for i = 1 to array.size(dates) - 1
        alert_text += str.tostring(array.get(dates     , i)) + ","+
                      str.tostring(array.get(sessionID , i)) + "," +
                      str.tostring(array.get(symbola , i)) + "," +
                      str.tostring(array.get(sesslengtha , i)) + "," +
                      str.tostring(array.get(ptopz      , i)) + "," +
                      str.tostring(array.get(pbottomz   , i)) + "," +
                      str.tostring(array.get(ptop2z     , i)) + "," +
                      str.tostring(array.get(pbtm2z     , i)) + "," +
                      str.tostring(array.get(nyopenarray1,i))+ ","+
                      str.tostring(array.get(nyopenarray2,i))+ ","+
                      str.tostring(array.get(nyclosearray1,i))+ ","+
                      str.tostring(array.get(nyclosearray2,i))+ ","+
                      str.tostring(array.get(nydayopena,i))+ ","+
                      str.tostring(array.get(nybarindexa,  i))+ ","+
                      str.tostring(array.get(signaldira,  i))+ ","+
                      str.tostring(array.get(signaltimea ,  i))+ ","+
                      str.tostring(array.get(highpa,  i))+ ","+
                      str.tostring(array.get(lowpa,  i))+ ","+
                      str.tostring(array.get(top2a, i))+ ","+
                      str.tostring(array.get(top2xa, i))+ ","+
                      str.tostring(array.get(fib1a,  i))+ ","+
                      str.tostring(array.get(fib1xa,  i))+ ","+
                      str.tostring(array.get(btm2a, i))+ ","+
                      str.tostring(array.get(btm2xa, i))+ ","+
                      str.tostring(array.get(fib4a,  i))+ ","+
                      str.tostring(array.get(fib4xa,  i))+ ","+
                      str.tostring(array.get(fib5a,  i))+ ","+
                      str.tostring(array.get(fib5xa,  i))+ ","+
                      str.tostring(array.get(fib6a,  i))+ ","+
                      str.tostring(array.get(fib6xa,  i))+ ","+
                      str.tostring(array.get(fib7a,  i))+ ","+
                      str.tostring(array.get(fib7xa,  i))+ ","+
                      str.tostring(array.get(fib3a,  i))+ ","+
                      str.tostring(array.get(fib3xa,  i))+ ","+
                      str.tostring(array.get(fib8a,  i))+ ","+
                      str.tostring(array.get(fib8xa,  i))+ ","+
                      str.tostring(array.get(bottoma, i))+ ","+
                      str.tostring(array.get(bottomxa, i))+ ","+
                      str.tostring(array.get(btm2aa, i))+ ","+
                      str.tostring(array.get(btm2xxa, i))+ ","+
                      str.tostring(array.get(fib1aa, i))+ ","+
                      str.tostring(array.get(fib1xxa, i))+ ","+
                      str.tostring(array.get(top2aa, i))+ ","+
                      str.tostring(array.get(top2xxa, i))+ ","+
                      str.tostring(array.get(fib9a,  i))+ ","+
                      str.tostring(array.get(fib9xa,  i))+ ","+
                      str.tostring(array.get(fib10a, i))+ ","+
                      str.tostring(array.get(fib10xa, i))+ ","+
                      str.tostring(array.get(fib11a, i))+ ","+
                      str.tostring(array.get(fib11xa, i))+ ","+
                      str.tostring(array.get(fib12a, i))+ ","+
                      str.tostring(array.get(fib12xa, i))+ ","+
                      str.tostring(array.get(fib2a,  i))+ ","+
                      str.tostring(array.get(fib2xa,  i))+ ","+
                      str.tostring(array.get(fib13a, i))+ "," +           
                      str.tostring(array.get(fib13xa, i))+ ","+            
                      str.tostring(array.get(topa, i))+ ","+
                      str.tostring(array.get(topxa, i))+ ";"
    alert(alert_text, freq = alert.freq_once_per_bar)

// LONDON ALERT
// if barstate.islast and dataalert and startarray2   
//     alerttextLDN = "Date,sess,symb,DR T,DR B,IDR T,IDR B,sessOO,sessOC,sessCO,sessCC,dayopen,nyC barNo,sigDir,sigbar,highp,lowp,idrbuy,idrbX,midbuy,midbuyx,idrbtmb,idrbtmbX,0.5b,0.5bX,1b,1bX,1.5b,1.5bX,2b,2X,2.5b,2.5X,3b,3bX,BStop,BStopX,idrS,idrSX,midsell,midsellx,idrtopS,idrtopsX,0.5s,0.5sX,1s,1sX,1.5S,1.5sx,2s,2sx,2.5s,2.5sx,3s,3sx,selstop,selstopX;\n"
//     for k = 1 to array.size(dates2) - 1
//         alerttextLDN += str.tostring(array.get(dates2     , k)) + "," +
//                          str.tostring(array.get(sessionID2 , k)) + "," +
//                          //str.tostring(array.get(symbola , k)) + "," +
//                          str.tostring(array.get(p2topz      , k)) + "," +
//                          str.tostring(array.get(p2bottomz   , k)) + "," +
//                          str.tostring(array.get(p2top2z     , k)) + "," +
//                          str.tostring(array.get(p2btm2z     , k)) + "," +
//                          str.tostring(array.get(ldnopenarray1,k))+ ","+
//                          str.tostring(array.get(ldnopenarray2,k))+ ","+
//                          str.tostring(array.get(ldnclosearray1,k))+ ","+
//                          str.tostring(array.get(ldnclosearray2,k))+ ","+
//                          //str.tostring(array.get(nydayopena,k))+ ","+
//                          str.tostring(array.get(ldnbarindexa,  k))+ ","+
//                          str.tostring(array.get(signaldira2,  k))+ ","+
//                          str.tostring(array.get(signaltime2,  k))+ ","+
//                          str.tostring(array.get(highpa2,  k))+ ","+
//                          str.tostring(array.get(lowpa2,  k))+ ","+
//                          str.tostring(array.get(top2a2, k))+ ","+
//                          str.tostring(array.get(top2xa2, k))+ ","+
//                          str.tostring(array.get(fib1a2,  k))+ ","+
//                          str.tostring(array.get(fib1xa2,  k))+ ","+
//                          str.tostring(array.get(btm2a2, k))+ ","+
//                          str.tostring(array.get(btm2xa2, k))+ ","+
//                          str.tostring(array.get(fib4a2,  k))+ ","+
//                          str.tostring(array.get(fib4xa2,  k))+ ","+
//                          str.tostring(array.get(fib5a2,  k))+ ","+
//                          str.tostring(array.get(fib5xa2,  k))+ ","+
//                          str.tostring(array.get(fib6a2,  k))+ ","+
//                          str.tostring(array.get(fib6xa2,  k))+ ","+
//                          str.tostring(array.get(fib7a2,  k))+ ","+
//                          str.tostring(array.get(fib7xa2,  k))+ ","+
//                          str.tostring(array.get(fib3a2,  k))+ ","+
//                          str.tostring(array.get(fib3xa2,  k))+ ","+
//                          str.tostring(array.get(fib8a2,  k))+ ","+
//                          str.tostring(array.get(fib8xa2,  k))+ ","+
//                          str.tostring(array.get(bottoma2, k))+ ","+
//                          str.tostring(array.get(bottomxa2, k))+ ","+
//                          str.tostring(array.get(btm2aa2, k))+ ","+
//                          str.tostring(array.get(btm2xxa2, k))+ ","+
//                          str.tostring(array.get(fib1aa2, k))+ ","+
//                          str.tostring(array.get(fib1xxa2, k))+ ","+
//                          str.tostring(array.get(top2aa2, k))+ ","+
//                          str.tostring(array.get(top2xxa2, k))+ ","+
//                          str.tostring(array.get(fib9a2,  k))+ ","+
//                          str.tostring(array.get(fib9xa2,  k))+ ","+
//                          str.tostring(array.get(fib10a2, k))+ ","+
//                          str.tostring(array.get(fib10xa2, k))+ ","+
//                          str.tostring(array.get(fib11a2, k))+ ","+
//                          str.tostring(array.get(fib11xa2, k))+ ","+
//                          str.tostring(array.get(fib12a2, k))+ ","+
//                          str.tostring(array.get(fib12xa2, k))+ ","+
//                          str.tostring(array.get(fib2a2,  k))+ ","+
//                          str.tostring(array.get(fib2xa2,  k))+ ","+
//                          str.tostring(array.get(fib13a2, k))+ "," +           
//                          str.tostring(array.get(fib13xa2, k))+ ","+            
//                          str.tostring(array.get(topa2, k))+ ","+
//                          str.tostring(array.get(topxa2, k))+ ";"
//     alert(alerttextLDN , freq = alert.freq_once_per_bar)
//TOKYO ALERT
// if barstate.islast and dataalert 
//     alerttextko = "Date,sess,symb,DR T,DR B,IDR T,IDR B,sessOO,sessOC,sessCO,sessCC,dayopen,nyC barNo,sigDir,sigbar,highp,lowp,idrbuy,idrbX,midbuy,midbuyx,idrbtmb,idrbtmbX,0.5b,0.5bX,1b,1bX,1.5b,1.5bX,2b,2X,2.5b,2.5X,3b,3bX,BStop,BStopX,idrS,idrSX,midsell,midsellx,idrtopS,idrtopsX,0.5s,0.5sX,1s,1sX,1.5S,1.5sx,2s,2sx,2.5s,2.5sx,3s,3sx,selstop,selstopX;\n"
//     for k = 1 to array.size(dates3) - 1
//         alerttextko +=  str.tostring(array.get(dates3     , k)) + "," +
//                          str.tostring(array.get(sessionID3 , k)) + "," +
//                          str.tostring(array.get(symbola , k)) + "," +
//                          str.tostring(array.get(p3topz      , k)) + "," +
//                          str.tostring(array.get(p3bottomz   , k)) + "," +
//                          str.tostring(array.get(p3top2z     , k)) + "," +
//                          str.tostring(array.get(p3btm2z     , k)) + "," +
//                          str.tostring(array.get(tyopenarray1,k))+ ","+
//                          str.tostring(array.get(tyopenarray2,k))+ ","+
//                          str.tostring(array.get(tyclosearray1,k))+ ","+
//                          str.tostring(array.get(tyclosearray2,k))+ ","+
//                          str.tostring(array.get(nydayopena,k))+ ","+
//                          str.tostring(array.get(tybarindexa,  k))+ ","+
//                          str.tostring(array.get(signaldira3,  k))+ ","+
//                          str.tostring(array.get(signaltime3,  k))+ ","+
//                          str.tostring(array.get(highpa3,  k))+ ","+
//                          str.tostring(array.get(lowpa3,  k))+ ","+
//                          str.tostring(array.get(top2a3, k))+ ","+
//                          str.tostring(array.get(top2xa3, k))+ ","+
//                          str.tostring(array.get(fib1a3,  k))+ ","+
//                          str.tostring(array.get(fib1xa3,  k))+ ","+
//                          str.tostring(array.get(btm2a3, k))+ ","+
//                          str.tostring(array.get(btm2xa3, k))+ ","+
//                          str.tostring(array.get(fib4a3,  k))+ ","+
//                          str.tostring(array.get(fib4xa3,  k))+ ","+
//                          str.tostring(array.get(fib5a3,  k))+ ","+
//                          str.tostring(array.get(fib5xa3,  k))+ ","+
//                          str.tostring(array.get(fib6a3,  k))+ ","+
//                          str.tostring(array.get(fib6xa3,  k))+ ","+
//                          str.tostring(array.get(fib7a3,  k))+ ","+
//                          str.tostring(array.get(fib7xa3,  k))+ ","+
//                          str.tostring(array.get(fib3a3,  k))+ ","+
//                          str.tostring(array.get(fib3xa3,  k))+ ","+
//                          str.tostring(array.get(fib8a3,  k))+ ","+
//                          str.tostring(array.get(fib8xa3,  k))+ ","+
//                          str.tostring(array.get(bottoma3, k))+ ","+
//                          str.tostring(array.get(bottomxa3, k))+ ","+
//                          str.tostring(array.get(btm2aa3, k))+ ","+
//                          str.tostring(array.get(btm2xxa3, k))+ ","+
//                          str.tostring(array.get(fib1aa3, k))+ ","+
//                          str.tostring(array.get(fib1xxa3, k))+ ","+
//                          str.tostring(array.get(top2aa3, k))+ ","+
//                          str.tostring(array.get(top2xxa3, k))+ ","+
//                          str.tostring(array.get(fib9a3,  k))+ ","+
//                          str.tostring(array.get(fib9xa3,  k))+ ","+
//                          str.tostring(array.get(fib10a3, k))+ ","+
//                          str.tostring(array.get(fib10xa3, k))+ ","+
//                          str.tostring(array.get(fib11a3, k))+ ","+
//                          str.tostring(array.get(fib11xa3, k))+ ","+
//                          str.tostring(array.get(fib12a3, k))+ ","+
//                          str.tostring(array.get(fib12xa3, k))+ ","+
//                          str.tostring(array.get(fib2a3,  k))+ ","+
//                          str.tostring(array.get(fib2xa3,  k))+ ","+
//                          str.tostring(array.get(fib13a3, k))+ "," +           
//                          str.tostring(array.get(fib13xa3, k))+ ","+            
//                          str.tostring(array.get(topa3, k))+ ","+
//                          str.tostring(array.get(topxa3, k))+ ";"
//     alert(alerttextko, freq = alert.freq_once_per_bar)


   

    //save
if not sessiontosession 
    if array1off 
        array1 := false
    if array2off
        array2 := false
    if array3off
        array3 := false
    
if sessiontosession  
    if array1off
        array2 := false
    if array2off
        array3 := false
    if array3off 
        array1 := false
