//@version=5
indicator("Gamma_Levels",overlay=true)
// 

txt = input.string("",title="Paste Downloaded Tradingview levels here",confirm=true)

offset = input.int(10,title="Label Offset ↔️ ")

Randomcolor=input.bool(false,title=" ")

color0=input.color(defval=color.rgb(255, 75, 237),              title="GEX Flip",           group="Fixed Colors")
color1=input.color(defval=color.rgb(255, 246, 72, 10),          title="GEX-0",              group="Fixed Colors")
color2=input.color(defval=color.rgb(255, 246, 72, 20),          title="GEX-1",              group="Fixed Colors")
color3=input.color(defval=color.rgb(255, 246, 72, 30),          title="GEX-2",              group="Fixed Colors")
color4=input.color(defval=color.rgb(255, 255, 72, 50),          title="GEX-3",              group="Fixed Colors")
color5=input.color(defval=color.rgb(76, 180, 255, 30),          title="+1STD (1-day)",      group="Fixed Colors")
color6=input.color(defval=color.rgb(76, 180, 255, 30),          title="-1STD (1-day)",      group="Fixed Colors")
color7=input.color(defval=color.rgb(76, 144, 175, 40),          title="+1STD (7-day)",      group="Fixed Colors")
color8=input.color(defval=color.rgb(76, 144, 175, 40),          title="-1STD (7-day)",      group="Fixed Colors")
color9=input.color(defval=color.rgb(76, 144, 175),              title="NA",                 group="Fixed Colors")

TxtToArray(string origin,string divider) =>
    Arr = array.new_string()
    Arr:= str.split(origin,divider)
    Arr

Dividedstrings=TxtToArray(txt,",")
color temporarycolor=na

plot(array.size(Dividedstrings)>=2 ? str.tonumber(array.get(Dividedstrings,1)) : na,title="first line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color0,display=display.price_scale)
plot(array.size(Dividedstrings)>=4 ? str.tonumber(array.get(Dividedstrings,3)) : na,title="second line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color1,display=display.price_scale)
plot(array.size(Dividedstrings)>=6 ? str.tonumber(array.get(Dividedstrings,5)) : na,title="third line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color2,display=display.price_scale)
plot(array.size(Dividedstrings)>=8 ? str.tonumber(array.get(Dividedstrings,7)) : na,title="fourth line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color3,display=display.price_scale)
plot(array.size(Dividedstrings)>=10 ? str.tonumber(array.get(Dividedstrings,9)) : na,title="fifth line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color4,display=display.price_scale)
plot(array.size(Dividedstrings)>=12 ? str.tonumber(array.get(Dividedstrings,11)) : na,title="sixth line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color5,display=display.price_scale)
plot(array.size(Dividedstrings)>=14 ? str.tonumber(array.get(Dividedstrings,13)) : na,title="seventh line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color6,display=display.price_scale)
plot(array.size(Dividedstrings)>=16 ? str.tonumber(array.get(Dividedstrings,15)) : na,title="eighth line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color7,display=display.price_scale)
plot(array.size(Dividedstrings)>=18 ? str.tonumber(array.get(Dividedstrings,17)) : na,title="ninth line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color8,display=display.price_scale)
plot(array.size(Dividedstrings)>=20 ? str.tonumber(array.get(Dividedstrings,19)) : na,title="tenth line",color=Randomcolor ? color.rgb(math.random(0,255),math.random(0,255),math.random(0,255)):color9,display=display.price_scale)

nb_bars = ta.barssince(time == chart.right_visible_bar_time)


if barstate.islastconfirmedhistory and array.size(Dividedstrings)!=0 
    for i=0 to array.size(Dividedstrings)-1
        
        if i%2==0
            temporarycolor:=color.rgb(math.random(0,255),math.random(0,255),math.random(0,255))
        if Randomcolor==false
            if i==0 or i==1 
                temporarycolor:=color0
            if i==2 or i==3
                temporarycolor:=color1
            if i==4 or i==5
                temporarycolor:=color2
            if i==6 or i==7
                temporarycolor:=color3
            if i==8 or i==9
                temporarycolor:=color4
            if i==10 or i==11
                temporarycolor:=color5
            if i==12 or i==13
                temporarycolor:=color6
            if i==14 or i==15
                temporarycolor:=color7
            if i==16 or i==17
                temporarycolor:=color8
            if i==18 or i==19
                temporarycolor:=color9
            
        if i%2==0
            label.new(bar_index+offset,str.tonumber(array.get(Dividedstrings,i+1)),array.get(Dividedstrings,i),xloc=xloc.bar_index,color=color.new(color.white,10),size=size.large,
             style=label.style_none,textcolor=temporarycolor,textalign=text.align_right)
        if i%2!=0
            line.new(bar_index,str.tonumber(array.get(Dividedstrings,i)),bar_index+1,str.tonumber(array.get(Dividedstrings,i)),
             extend=extend.both,color=temporarycolor)


//plot(nb_bars,display =display.status_line )