RESISTANCE & SUPPORT
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jadeja_rajdeep

//@version=5
indicator("RESISTANCE & SUPPORT",overlay=true,max_lines_count=20,max_bars_back=254)

ema10 = ta.ema(close,10)
ema21 = ta.ema(close,21)
sma50 = ta.sma(close,50)
sma100 = ta.sma(close,100)

downcolor=input.color(color.red,"Pullback Line","","Line Color")
upcolor=input.color(color.green,"Rising Line","","Line Color")
vcolor=input.color(color.blue,"Vshape Line","","Line Color")
bar2color=input.color(#ff9800,"2 Bar Fail","","Line Color")
bar2_reversal_color=input.color(#00865a,"2 Bar Reversal","","Line Color")
insidebar_reversal_color=input.color(color.rgb(255, 0, 221),"Inside Bar Reversal","","Line Color")

showlable=input.bool(true,"Show Line Counter")
downvisible=input.bool(true,"Pullback Line")
upvisible=input.bool(true,"Rising Line")
vvisible=input.bool(true,"Vshape Line")
bar2visible=input.bool(true,"2 Bar Fail Line")
bar2_reversal_visible=input.bool(true,"2 Bar Reversal")
insidebar_reversal_visible=input.bool(true,"Inside Bar Reversal")

var linecounter = 0

get_line_counter(linecounter) =>
    linecounter+1

if (high >= sma50 or (close>=sma100 and ema21>=sma100 and sma50>=sma100))
    if(bar2_reversal_visible==true)
        if(close[1]<close[2] and close[2]<close[3] and close>=high[1])
            line.new(x1=bar_index-1,y1=high[1],x2=bar_index,y2=high[1],xloc=xloc.bar_index,extend=extend.right,style=line.style_dashed,color=bar2_reversal_color)
            if(showlable==true)
                linecounter := get_line_counter(linecounter)
                label.new(x=bar_index-1,y = high[1],text= str.tostring(linecounter)+" - BUY @ "+str.tostring(math.round(high[1],2)), xloc=xloc.bar_index, yloc=yloc.price,color=bar2_reversal_color, style=label.style_label_down , textcolor=#ffffff,size = size.small)

    if(insidebar_reversal_visible==true)
        inside_bar=0
        mainbar_high=high[10]
        mainbar_low=low[10]
        if(close>=high[1] and close[1] < high[2] and mainbar_high>= ta.highest(math.max(open[1],close[1]),10) and mainbar_low <= ta.lowest(math.min(open[1],close[1]),10))
            inside_bar := 1
        
        if(inside_bar==0)
            mainbar_high :=high[9]
            mainbar_low :=low[9]
            if(close>=high[1] and close[1] < high[2] and mainbar_high>= ta.highest(math.max(open[1],close[1]),9) and mainbar_low <= ta.lowest(math.min(open[1],close[1]),9))
                inside_bar := 1

        if(inside_bar==0)
            mainbar_high :=high[8]
            mainbar_low :=low[8]
            if(close>=high[1] and close[1] < high[2] and mainbar_high>= ta.highest(math.max(open[1],close[1]),8) and mainbar_low <= ta.lowest(math.min(open[1],close[1]),8))
                inside_bar := 1

        if(inside_bar==0)
            mainbar_high :=high[7]
            mainbar_low :=low[7]
            if(close>=high[1] and close[1] < high[2] and mainbar_high>= ta.highest(math.max(open[1],close[1]),7) and mainbar_low <= ta.lowest(math.min(open[1],close[1]),7))
                inside_bar := 1

        if(inside_bar==0)
            mainbar_high :=high[6]
            mainbar_low :=low[6]
            if(close>=high[1] and close[1] < high[2] and mainbar_high>= ta.highest(math.max(open[1],close[1]),6) and mainbar_low <= ta.lowest(math.min(open[1],close[1]),6))
                inside_bar := 1

        if(inside_bar==0)
            mainbar_high :=high[5]
            mainbar_low :=low[5]
            if(close>=high[1] and close[1] < high[2] and mainbar_high>= ta.highest(math.max(open[1],close[1]),5) and mainbar_low <= ta.lowest(math.min(open[1],close[1]),5))
                inside_bar := 1

        if(inside_bar==0)
            mainbar_high :=high[4]
            mainbar_low :=low[4]
            if(close>=high[1] and close[1] < high[2] and mainbar_high>= ta.highest(math.max(open[1],close[1]),4) and mainbar_low <= ta.lowest(math.min(open[1],close[1]),4))
                inside_bar := 1

        if(inside_bar==0)
            mainbar_high :=high[3]
            mainbar_low :=low[3]
            if(close>=high[1] and close[1] < high[2] and mainbar_high>= ta.highest(math.max(open[1],close[1]),3) and mainbar_low <= ta.lowest(math.min(open[1],close[1]),3))
                inside_bar := 1
        
        if(inside_bar==1)
            line.new(x1=bar_index-1,y1=high[1],x2=bar_index,y2=high[1],xloc=xloc.bar_index,extend=extend.right,style=line.style_dashed,color=insidebar_reversal_color)
            if(showlable==true)
                linecounter := get_line_counter(linecounter)
                label.new(x=bar_index-1,y = high[1],text= str.tostring(linecounter)+" - BUY @ "+str.tostring(math.round(high[1],2)), xloc=xloc.bar_index, yloc=yloc.price,color=insidebar_reversal_color, style=label.style_label_down , textcolor=#ffffff,size = size.small)


if (ema10 >= ema21 and ema21 >= sma50)
    if(bar2visible==true)
        if(volume <= volume[1])
            if(close < open and close[1] >= open[1] and open >= close[1] and close < close[1])
                line.new(x1=bar_index-1,y1=high,x2=bar_index,y2=high,xloc=xloc.bar_index,extend=extend.right,style=line.style_solid,color=bar2color)
                if(showlable==true)
                    linecounter := get_line_counter(linecounter)
                    label.new(x=bar_index,y = high,text= str.tostring(linecounter), xloc=xloc.bar_index, yloc=yloc.price,color=bar2color, style=label.style_label_down , textcolor=#ffffff,size = size.small)
    if(volume[2] >= volume[1] and volume[1] >= volume)
        if(downvisible==true)
            if(close[2] >= close[1] and close[1] >= close)
                line.new(x1=bar_index-1,y1=high,x2=bar_index,y2=high,xloc=xloc.bar_index,extend=extend.right,style=line.style_dashed,color=downcolor)
                if(showlable==true)
                    linecounter := get_line_counter(linecounter)
                    label.new(x=bar_index,y = high,text= str.tostring(linecounter), xloc=xloc.bar_index, yloc=yloc.price,color=downcolor, style=label.style_label_down , textcolor=#ffffff,size = size.small)
        if(upvisible==true)
            if(close > close[1] and close[1] > close[2])
                line.new(x1=bar_index-1,y1=high,x2=bar_index,y2=high,xloc=xloc.bar_index,extend=extend.right,style=line.style_solid,color=upcolor)
                if(showlable==true)
                    linecounter := get_line_counter(linecounter)
                    label.new(x=bar_index,y = high,text= str.tostring(linecounter), xloc=xloc.bar_index, yloc=yloc.price,color=upcolor, style=label.style_label_down , textcolor=#ffffff,size = size.small)
        if(vvisible==true)
            if(close > close[1] and close[1] < close[2])
                line.new(x1=bar_index-1,y1=high,x2=bar_index,y2=high,xloc=xloc.bar_index,extend=extend.right,style=line.style_dotted,color=vcolor)
                if(showlable==true)
                    linecounter := get_line_counter(linecounter)
                    label.new(x=bar_index,y = high,text= str.tostring(linecounter), xloc=xloc.bar_index, yloc=yloc.price,color=vcolor, style=label.style_label_down , textcolor=#ffffff,size = size.small)
