Trend Lines [AstroHub]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

//@version=5
indicator("Trend Lines [AstroHub]", overlay=true)

// Input parameters
lookback = input(20, "Period")

// Determining the high and low prices
highs = ta.highest(high, lookback)
lows = ta.lowest(low, lookback)

// Determining the trend lines
trendLineUp = ta.valuewhen(high == highs, high, 0)
trendLineDown = ta.valuewhen(low == lows, low, 0)

// Determining the bar color
barColor = close > (trendLineUp + trendLineDown) / 2 ? color.green : color.red

// Drawing the lines and changing the bar color
plot(trendLineUp, color=color.green, linewidth=2)
plot(trendLineDown, color=color.red, linewidth=2)
barcolor(barColor)

// RSI indicator
rsiLength = input(13, "RSI Length")
overboughtLevel = input(70, "Overbought Level")
oversoldLevel = input(20, "Oversold Level")
rsi = ta.rsi(close, rsiLength)

// Determine the RSI signal for trend reversal
rsiSignal = rsi > overboughtLevel ? 1 : rsi < oversoldLevel ? -1 : 0

// Plot the RSI signal on the chart
plotshape(rsiSignal == 1 ? low : na, style=shape.triangledown, color=color.red, size=size.small)
plotshape(rsiSignal == -1 ? high : na, style=shape.triangleup, color=color.green, size=size.small)

