[FrizLabz]PB OLvls
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FFriZz

//@version=5
indicator('[FrizLabz]PB OLvls','[FrizLabz]PB OLvls',overlay=true,max_lines_count = 500,max_boxes_count = 500,max_labels_count = 500,max_bars_back = 500,explicit_plot_zorder = true)

days_i  = input.int(1,'Days Visable',minval = 1)
regMarket_i = input.bool(true,'Reg. Market Opens')
color_i = input.color(#ffa500,'Reg Market Color')
preMarket_i = input.bool(true,'Premarket Opens')
colorP_i = input.color(#800080,'Pre Market Color')
label_i  = input.bool(true,'Label On/Off')
format_i = input.string('E | MM-dd-yyyy','Label Format',tooltip = 'You can google "java date formatting" to find formatting examples')

var line[]  aLine  = array.new<line>()
var label[] aLabel = array.new<label>()
var line[]  aLineP  = array.new<line>()
var label[] aLabelP = array.new<label>()

formattedDate(series float timeInMs, series string format = "E | MM-dd-yyyy") =>
    string result = str.format("{0,date," + format + "}", int(timeInMs))

if session.isfirstbar_regular and regMarket_i
    if bar_index > 500
        array.push(aLine,line.new(bar_index,open,last_bar_index + 20,open,xloc.bar_index,extend.none, color_i,line.style_solid,1))
        if label_i
            array.push(aLabel,label.new(last_bar_index + 20,open, 
             '[' + formattedDate(time,format_i) + ' | ' + str.tostring(open) + ']', style = label.style_label_left, color = color(na), textcolor = color_i,size = size.small))
        
    if array.size(aLine) > days_i
        line.delete(array.shift(aLine))
        if label_i
            label.delete(array.shift(aLabel))
    
if session.isfirstbar and preMarket_i
    if bar_index > 500
        array.push(aLineP,line.new(bar_index,open,last_bar_index + 20,open,xloc.bar_index,extend.none, colorP_i,line.style_solid,1))
        if label_i
            array.push(aLabelP,label.new(last_bar_index + 20,open, 
             '[' + formattedDate(time,format_i) + ' | ' + str.tostring(open) + ']', style = label.style_label_left, color = color(na), textcolor = colorP_i,size = size.small))
        
    if array.size(aLineP) > days_i
        line.delete(array.shift(aLineP))
        if label_i
            label.delete(array.shift(aLabelP))
    
// 

