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

//@version=5
indicator("Range Slicer",overlay = true)
p1=input.price(100.0,title="Price Level One",tooltip = "Select Price Level Point 1 on Chart ",confirm = true)
p2=input.price(50.0,title="Price Level Two",tooltip = "Select Price Level Point 2 on Chart ",confirm = true)

slices=input.int(5,title="Number of slices")
pr_col=input.color(color.teal,title="Price Range Line Color",inline = "+")
pr_lw=input.int(2,title="Price Range Line Width",inline = "+")
slice_col=input.color(color.purple,title="Slice Line Color",inline = "=")
slice_lw=input.int(1,title="Slice Line Width",inline = "=")
ext=input.string(defval = "To Right",options = ["To Right","Both"],title="Extend lines: ", inline="c")

var p1Line=line.new(1,1,1,1,color=pr_col,extend=ext=="Both"?extend.both:extend.right,width=pr_lw)
var p2Line=line.new(1,1,1,1,color=pr_col,extend=ext=="Both"?extend.both:extend.right,width = pr_lw)
var sliceLines = array.new<line>(slices)

topVal=math.max(p1,p2)
bottomVal=math.min(p1,p2)
priceRange=topVal-bottomVal
sliceSize=priceRange/slices
line.set_xy1(p1Line,bar_index,p1),line.set_xy2(p1Line,bar_index+1,p1)
line.set_xy1(p2Line,bar_index,p2),line.set_xy2(p2Line,bar_index+1,p2)
line.set_extend(p1Line,ext=="Both"?extend.both:extend.right), line.set_extend(p2Line,ext=="Both"?extend.both:extend.right)

if array.size(sliceLines)>0 and barstate.isconfirmed
    for i=0 to array.size(sliceLines)-1
        line.delete(array.get(sliceLines,i))
array.clear(sliceLines)
sliceLines:=array.new<line>(slices) 

if barstate.isconfirmed
    for i=1 to slices-1 
        level=(sliceSize*i)+bottomVal
        line=line.new(bar_index,level,bar_index+6,level,color=slice_col,extend=ext=="Both"?extend.both:extend.right,width = slice_lw)
        array.insert(sliceLines,i,line)






