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

//@version=5
indicator("InsideBar3.0", overlay = true)
var float h1=na
var float l1 = na
var int mindex=na
var float target1 = na
var float target2 = na
var float target3 = na
var float target4 = na


insidebar()=> ( high<high[1] and low>low[1] )

//high<high[1] and low >low[1]

ins=insidebar()
if insidebar()
// if high < high[1] and low >low[1]
    h1 := high[1]
    l1 := low[1]
    mindex:=bar_index[1]
    target1:= h1+(h1-l1)
    target2:=h1+2*(h1-l1)
    target3:=l1-(h1-l1)
    target4:=l1-(2*(h1-l1))
//if high <= high[1] and low >= low[1]
   
barcolor(ins? color.yellow: close>open? color.green:color.red)

hiline=line.new(mindex, h1, bar_index, h1, color=color.green, extend=extend.right, width = 2)
line.delete(hiline[1])
loline=line.new(mindex, l1, bar_index, l1, color=color.red, extend=extend.right, width = 2)
line.delete(loline[1])
linefill.new(hiline, loline, color=color.new(color.purple, 90))
targetline=close>h1?line.new(mindex, target1, bar_index, target1, color=color.aqua, extend=extend.right, width = 2, style=line.style_dotted):line.new(mindex, target3, bar_index, target3, color=color.aqua, extend=extend.right, width = 2, style=line.style_dotted)
lable1=close>h1?label.new(mindex, target1, text="Target1", color=color.blue, textcolor = color.white, style=label.style_none):label.new(mindex, target3, text="Target1", color=color.blue, textcolor = color.white, style=label.style_none)
label.delete(lable1[1])
line.delete(targetline[1])
targetline2=close>h1?line.new(mindex, target2, bar_index, target2, color=color.fuchsia, extend=extend.right, width = 2, style=line.style_dotted):line.new(mindex, target4, bar_index, target4, color=color.fuchsia, extend=extend.right, width = 2, style=line.style_dotted)
line.delete(targetline2[1])
lable2=close>h1?label.new(mindex, target2, text="Target2", color=color.blue, textcolor = color.white, style=label.style_none):label.new(mindex, target4, text="Target2", color=color.blue, textcolor = color.white, style=label.style_none)
label.delete(lable2[1])

