Reversal picker
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Gudanin

//@version=5
indicator("Reversal picker", overlay = true)


//line variables

line1 = ta.sma(close, 14)
line2 = ta.sma(close, 200)
highrsi = ta.rsi(close,14) > 50
lowrsi = ta.rsi(close,14) < 50


line11 = ta.sma(close, 19)
line22 = ta.sma(close, 21)

highrsi1 = ta.rsi(close,14) >= 65
lowrsi1 = ta.rsi(close,14) <= 35


//Reversal logic

BuyP= line11 > line22 and highrsi1 and line1 > line2 and highrsi

var label up = na
var label down = na
var line l = na
var float first_close = na
var bool can_draw = false

var line l1 = na
var float first_close1 = na
var bool can_draw1 = false

//support and resistance line colors
color supportlinecolor = input.color(color.green, "Support line color")
color resistancelinecolor = input.color(color.red, "Resistance line color")

//label colors
color buylabelcolor = input.color(color.green, "Buy label color")
color selllabelcolor = input.color(color.red, "Sell label color")

//text colors
color buylabeltextcolor = input.color(color.white, "Buy label text color")
color selllabeltextcolor = input.color(color.white, "Sell label text color")



if(line11 > line22 and highrsi1 and line1 > line2 and highrsi)
    first_close := close  // Reset session high
    can_draw := true    // We are allowed to draw a line
    l := line.new(bar_index-1, first_close, bar_index, first_close, color=resistancelinecolor, xloc = xloc.bar_index, extend = extend.both,width=2) 
    line.delete(l[1])
   
    if(na(up)) //Does not exist, create one
        up := label.new(bar_index, close, "Price reversing \n Sell below resistance line", color=selllabelcolor, yloc=yloc.abovebar, textcolor = selllabeltextcolor)
        
                
            
            
       
    else
        label.set_x(up, bar_index)


if(line11 < line22 and lowrsi and line1 < line2 and lowrsi )
    first_close1 := open  // Reset session high
    can_draw1 := true    // We are allowed to draw a line
    l1 := line.new(bar_index-1, first_close1, bar_index, first_close1, color=supportlinecolor, xloc = xloc.bar_index, extend = extend.both,width=2) 
    line.delete(l1[1])
    if(na(down)) //Does not exist, create one
        down := label.new(bar_index, close, "Price reversing \n Buy above support line", color=buylabelcolor, yloc=yloc.belowbar, style = label.style_label_up, textcolor = buylabeltextcolor)
    else
        label.set_x(down, bar_index)  

    

