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

//@version=5
indicator("Ayvebotem",overlay=true,shorttitle="Ayve")
Ay1=ta.highest(40) 
Ay2=ta.lowest(40)
leftBars = input(20)
rightBars=input(20)
Ay3 = ta.pivothigh(leftBars, rightBars)
[supertrend, direction] = ta.supertrend(3, 10)
plot(direction < 40 ? supertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(direction > 40 ? supertrend : na, "Down direction", color = color.red, style=plot.style_linebr)
plot(Ay1)
plot(Ay2)
plot(Ay3)
pine_sar(start, inc, max) =>
	var float result = na
	var float maxMin = na
	var float acceleration = na
	var bool isBelow = na
	bool isFirstTrendBar = false
	
	if bar_index == 1
		if close > close[1]
			isBelow := true
			maxMin := high
			result := low[1]
		else
			isBelow := false
			maxMin := low
			result := high[1]
		isFirstTrendBar := true
		acceleration := start
	
	result := result + acceleration * (maxMin - result)
	
	if isBelow
		if result > low
			isFirstTrendBar := true
			isBelow := false
			result := math.max(high, maxMin)
			maxMin := low
			acceleration := start
	else
		if result < high
			isFirstTrendBar := true
			isBelow := true
			result := math.min(low, maxMin)
			maxMin := high
			acceleration := start
			
	if not isFirstTrendBar
		if isBelow
			if high > maxMin
				maxMin := high
				acceleration := math.min(acceleration + inc, max)
		else
			if low < maxMin
				maxMin := low
				acceleration := math.min(acceleration + inc, max)
	
	if isBelow
		result := math.min(result, low[1])
		if bar_index > 1
			result := math.min(result, low[2])
		
	else
		result := math.max(result, high[1])
		if bar_index > 1
			result := math.max(result, high[2])
	
	result
	
plot(pine_sar(0.02, 0.02, 0.2), style=plot.style_cross, linewidth=3)

rsi_on = input.bool(false, "+ RSI")
l_bar = input.int(150, "(BUY) Lowest Bar", minval=1)
rsi_low_value = input.int(27, "(BUY) RSI value <")
sell_on = input.bool(true, "+ SELL")
h_bar = input.int(150, "(SELL) Highest Bar", minval=1)
rsi_high_value = input.int(73, "(SELL) RSI value >")
rsi = ta.rsi(close, 14)
lowclosebar = ta.lowestbars(close, l_bar)
highclosebar = ta.highestbars(close, h_bar)
color labelbuy = color(color.green)
color labelsell = color(color.red)

buy_condition = lowclosebar == 0 and rsi_on == false
buy_condition_rsi = lowclosebar == 0 and rsi_on == true and rsi < rsi_low_value

sell_condition = highclosebar == 0 and rsi_on == false and sell_on
sell_condition_rsi = highclosebar == 0 and rsi_on == true and rsi > rsi_high_value and sell_on

if buy_condition
    label.new(bar_index, low, yloc = yloc.belowbar, color=labelbuy, style=label.style_triangleup, size=size.tiny)
    
if buy_condition_rsi
    label.new(bar_index, low, yloc = yloc.belowbar, color=labelbuy, style=label.style_triangleup, size=size.tiny)
    
if sell_condition 
    label.new(bar_index, low, yloc = yloc.abovebar, color=labelsell, style=label.style_triangledown, size=size.tiny)
    
if sell_condition_rsi
    label.new(bar_index, low, yloc = yloc.abovebar, color=labelsell, style=label.style_triangledown, size=size.tiny)
    
alertcondition(buy_condition or buy_condition_rsi, title="Low Price Detected", message="Low Price Detected")
alertcondition(sell_condition or sell_condition_rsi, title="High Price Detected", message="High Price Detected")







































