TradingView Party
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © barnabygraham
// © HeWhoMustNotBeNamed
// © RicardoSantos

//@version=5
indicator("TradingView Party",max_boxes_count = 500,max_lines_count = 500,max_labels_count = 500,overlay=true)

i_preset = input.string('Custom', title='Background', options=['Light', 'Dark', 'Light+Dark', 'Custom'])
i_h_min = input.int(0, minval=0, maxval=127, title='H', group='HSLT', inline='H')
i_h_max = input.int(255, minval=128, maxval=255, title='', group='HSLT', inline='H')
i_s_min = input.int(50, minval=0, maxval=50, title='S', group='HSLT', inline='S')
i_s_max = input.int(100, minval=51, maxval=100, title='', group='HSLT', inline='S')
i_l_min = input.int(20, minval=0, maxval=51, title='L', group='HSLT', inline='L')
i_l_max = input.int(100, minval=51, maxval=100, title='', group='HSLT', inline='L')
i_transparency = input.int(0, minval=0, maxval=100, title='T', group='HSLT', inline='T')

// ************** This part of the code is taken from // © RicardoSantos
// https://www.tradingview.com/script/4jdGt6Xo-Function-HSL-color/
f_color_hsl(_hue, _saturation, _lightness, _transparency) =>  //{
//  @function: returns HSL color.
//  @reference: https://stackoverflow.com/questions/36721830/convert-hsl-to-rgb-and-hex
    float _l1 = _lightness / 100.0
    float _a = _saturation * math.min(_l1, 1.0 - _l1) / 100.0
    float _rk = (0.0 + _hue / 30.0) % 12.0
    float _r = 255.0 * (_l1 - _a * math.max(math.min(_rk - 3.0, 9.0 - _rk, 1.0), -1.0))
    float _gk = (8.0 + _hue / 30.0) % 12.0
    float _g = 255.0 * (_l1 - _a * math.max(math.min(_gk - 3.0, 9.0 - _gk, 1.0), -1.0))
    float _bk = (4.0 + _hue / 30.0) % 12.0
    float _b = 255.0 * (_l1 - _a * math.max(math.min(_bk - 3.0, 9.0 - _bk, 1.0), -1.0))
    color.rgb(_r, _g, _b, _transparency)  // 
//}
// ************** End of borrowed code

// This part of the code was taken from © HeWhoMustNotBeNamed's random color generator
avoidLight = i_preset == 'Light' or i_preset == 'Light+Dark'
avoidDark = i_preset == 'Dark' or i_preset == 'Light+Dark'
custom = i_preset == 'Custom'
l_min = custom ? i_l_min : avoidDark ? 30 : 0
l_max = custom ? i_l_max : avoidLight ? 70 : 100

h_min = custom ? i_h_min : 0
h_max = custom ? i_h_max : 255

s_min = custom ? i_s_min : 0
s_max = custom ? i_s_max : 100


f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, transparency) =>
    f_color_hsl(math.random(h_min, h_max), math.random(s_min, s_max), math.random(l_min, l_max), transparency)
// End of borrowed code


n = bar_index


lineStyle(x) =>
    output = x == 1 ? line.style_solid : 
     x == 2 ? line.style_dotted : 
     x == 3 ? line.style_dashed :
     x == 4 ? line.style_arrow_left :
     x == 5 ? line.style_arrow_right : line.style_arrow_both

boxStyle(x) =>
    output = x == 1 ? line.style_solid : 
     x == 2 ? line.style_dotted : line.style_dashed

textSize(x) =>
    output = x == 1 ? size.auto : 
     x == 2 ? size.tiny : 
     x == 3 ? size.small :
     x == 4 ? size.normal : 
     x == 5 ? size.large : size.huge



line1 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line2 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line3 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line4 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line5 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line6 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line7 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line8 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line9 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line10 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line11 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line12 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line13 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line14 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line15 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line16 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line17 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line18 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line19 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))
line20 = line.new(n-int(math.random(0,100)),close,n-int(math.round(math.random(0,100),0)),close[int(math.round(math.random(0,100),0))],extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),style=lineStyle(int(math.random(1,6))),width=int(math.random(0,10)))

line.delete(line1[1])
line.delete(line2[1])
line.delete(line3[1])
line.delete(line4[1])
line.delete(line5[1])
line.delete(line6[1])
line.delete(line7[1])
line.delete(line8[1])
line.delete(line9[1])
line.delete(line10[1])
line.delete(line11[1])
line.delete(line12[1])
line.delete(line13[1])
line.delete(line14[1])
line.delete(line15[1])
line.delete(line16[1])
line.delete(line17[1])
line.delete(line18[1])
line.delete(line19[1])
line.delete(line20[1])



box1loc = n+int(math.random(-100,200))
box2loc = n+int(math.random(-200,100))
box3loc = n+int(math.random(-300,0))
box4loc = n+int(math.random(-400,-100))
box5loc = n+int(math.random(-500,-200))
box6loc = n+int(math.random(-600,-300))
box7loc = n+int(math.random(-700,-400))
box8loc = n+int(math.random(-800,-500))
box9loc = n+int(math.random(-900,-600))
box10loc = n+int(math.random(-1000,-700))
box1 = box.new(box1loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box2 = box.new(box2loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box3 = box.new(box3loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box4 = box.new(box4loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box5 = box.new(box5loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box6 = box.new(box6loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box7 = box.new(box7loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box8 = box.new(box8loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box9 = box.new(box9loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box10 = box.new(box10loc-int(math.random(math.random(0,10),math.random(0,100))),close*math.random(1,1.01),box1loc+int(math.random(1,100)),close*math.random(0.99,1),f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),int(math.random(0,10)),boxStyle(int(math.random(1,3))),extend.none,bgcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency+90+math.random(0,10)))
box.delete(box1[1])
box.delete(box2[1])
box.delete(box3[1])
box.delete(box4[1])
box.delete(box5[1])
box.delete(box6[1])
box.delete(box7[1])
box.delete(box8[1])
box.delete(box9[1])
box.delete(box10[1])


verticalLine1 = line.new(n+int(math.round(math.random(-100,100,2),0)),low,n+int(math.round(math.random(-100,100,2),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine2 = line.new(n+int(math.round(math.random(-100,100,3),0)),low,n+int(math.round(math.random(-100,100,3),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine3 = line.new(n+int(math.round(math.random(-100,100,4),0)),low,n+int(math.round(math.random(-100,100,4),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine4 = line.new(n+int(math.round(math.random(-100,100,5),0)),low,n+int(math.round(math.random(-100,100,5),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine5 = line.new(n+int(math.round(math.random(-100,100,6),0)),low,n+int(math.round(math.random(-100,100,6),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine6 = line.new(n+int(math.round(math.random(-100,100,7),0)),low,n+int(math.round(math.random(-100,100,7),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine7 = line.new(n+int(math.round(math.random(-100,100,8),0)),low,n+int(math.round(math.random(-100,100,8),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine8 = line.new(n+int(math.round(math.random(-100,100,9),0)),low,n+int(math.round(math.random(-100,100,9),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine9 = line.new(n+int(math.round(math.random(-100,100,10),0)),low,n+int(math.round(math.random(-100,100,10),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
verticalLine10 = line.new(n+int(math.round(math.random(-100,100,11),0)),low,n+int(math.round(math.random(-100,100,11),0)),high,extend=extend.both,color=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),width=int(math.random(0,30)))
line.delete(verticalLine1[1])
line.delete(verticalLine2[1])
line.delete(verticalLine3[1])
line.delete(verticalLine4[1])
line.delete(verticalLine5[1])
line.delete(verticalLine6[1])
line.delete(verticalLine7[1])
line.delete(verticalLine8[1])
line.delete(verticalLine9[1])
line.delete(verticalLine10[1])

labelText(x) =>
    output = x == 1 ? 'Party!' :
     x == 2 ? 'Yeah!' : 
     x == 3 ? 'Woohoo!' : 
     x == 4 ? 'Alright!' :
     x == 5 ? 'Yippee!' :
     x == 6 ? 'Incredible!' :
     x == 7 ? 'Wow!' :
     x == 8 ? 'Really neato!' : 
     x == 9 ? '☜(⌒▽⌒)☞' : 
     x == 10 ? '◖♪_♪|◗' : 
     x == 11 ? '＼(^。^ )' : 
     x == 12 ? '((ヽ(๑╹◡╹๑)ﾉ))♬' :
     x == 13 ? '(☞ﾟヮﾟ)☞   ☜(ﾟヮﾟ☜)' :
     x == 14 ? '👉😎👉' : 
     x == 15 ? '(☞ ͡° ͜ʖ ͡°)☞' : 
     x == 16 ? '🥳🙌🎂 🍰🎈🎉 🎁' : 
     x == 17 ? '(((o(*ﾟ▽ﾟ*)o)))' : 'ヾ(⌐■_■)ノ♪'

label1 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label2 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label3 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label4 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label5 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label6 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label7 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label8 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label9 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label10 = label.new(n+int(math.random(-100,100)),close[int(math.random(0,50))],labelText(int(math.random(1,18))),style=label.style_flag,textcolor=f_random_color(h_min, h_max, s_min, s_max, l_min, l_max, i_transparency),color=color.new(color.white,100),size=textSize(int(math.random(1,6))))
label.delete(label1[1])
label.delete(label2[1])
label.delete(label3[1])
label.delete(label4[1])
label.delete(label5[1])
label.delete(label6[1])
label.delete(label7[1])
label.delete(label8[1])
label.delete(label9[1])
label.delete(label10[1])
