Parabolic Zones
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © UzairTahir

//@version=5
indicator("Parabolic Zonesusd", overlay=true)

start = input(0.02)
increment = input(0.02)
maximum = input(0.2, "Max Value")
sar_values = ta.sar(start, increment, maximum)

sar_value_candle0 = sar_values[0]
sar_value_candle1 = sar_values[1]
//log.info(str.tostring(sar_value_candle1))
//length = input.int(500, title="Line length")
width  = input.int(1, title ="Line Width")
//Number of Bars 
lastBarsFilterInput  = input.int(500, title ="Plotting on past candles")
styleOption = input.string("solid (─)", title="Line Style",
     options=["solid (─)", "dotted (┈)", "dashed (╌)", 
     "arrow left (←)", "arrow right (→)", "arrows both (↔)"])
// STEP 2. Convert the input to a proper line style value
lineStyle = styleOption == "dotted (┈)" ? line.style_dotted :
     styleOption == "dashed (╌)" ? line.style_dashed :
     styleOption == "arrow left (←)" ? line.style_arrow_left :
     styleOption == "arrow right (→)" ? line.style_arrow_right :
     styleOption == "arrows both (↔)" ? line.style_arrow_both :
         line.style_solid     
line = input(title="Show PSAR/SR Reversal? ", defval=true)         
red_line = input(title="Red Line ", defval=true)
green_line = input(title="Green Line ", defval=true)

high_of_candle0 = high[0]
low_of_candle0 = low[0]
high_of_candle1 = high[1]
low_of_candle1 = low[1]


var lastbar = last_bar_index
allowedToTrade = (lastbar - bar_index <= lastBarsFilterInput) or barstate.isrealtime

if(low_of_candle1 >= sar_value_candle1 and high_of_candle0 <= sar_value_candle0 and allowedToTrade == true)
    alert("Alert in buy zone", alert.freq_once_per_bar_close)
    if(line == true and red_line == true)
        buy_line = line.new(x1=bar_index-1, y1=sar_value_candle1, x2=bar_index, y2=sar_value_candle1, color=color.rgb(188, 14, 14), width=width, style=lineStyle) //x2=bar_index+length
        // Extend the line forever to the right
        line.set_extend(id=buy_line, extend=extend.right)
else if(high_of_candle1 <= sar_value_candle1 and low_of_candle0 >= sar_value_candle0 and allowedToTrade == true)
    alert("Alert in Sell Zone", alert.freq_once_per_bar_close)
    if(line == true and green_line == true)
        sell_line = line.new(x1=bar_index-1, y1=sar_value_candle1, x2=bar_index, y2=sar_value_candle1, color=#27d73b, width=width, style=lineStyle) //x2=bar_index+length
        // Extend the line forever to the right
        line.set_extend(id = sell_line, extend = extend.right)