TCG AI Tools
// 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('TCG AI Tools')

// Rule 1: Price trend
long_ema = ta.sma(close, 10)
short_ema = ta.sma(close, 20)

trend = short_ema > long_ema ? 1 : 0

// Plotting the trend indicator as a line on the chart
trend_color = trend == 1 ? color.red : color.green
plot(0, color=trend_color, style=plot.style_line, linewidth=40)

price = input(close, title='Price')
bb_length = input(20, title='Bollinger length')
bb_multiplier = input(2, title='Bollinger Multiplier')
// BB
bb_basis = ta.sma(price, bb_length)
bb_dev = bb_multiplier * ta.stdev(price, bb_length)
bb_upper = bb_basis + bb_dev
bb_lower = bb_basis - bb_dev
// Plots

bbc = ta.crossover(price, bb_upper) ? float(0) : float(na)
plotshape(bbc, title='BB Cross', style=shape.triangledown, color=color.rgb(255, 105, 105), size=size.normal, location=location.absolute)
bbd = ta.crossover(price, bb_lower) ? float(0) : float(na)
plotshape(bbd, title='BB Cross', style=shape.triangleup, color=color.rgb(97, 255, 103), size=size.normal, location=location.absolute)

//RSI Overbought.  Green and Red Background & Blue/Purple bars
inp_overbought = input.int(defval=70, title='Overbought', minval=1)
inp_oversold = input.int(defval=30, title='Oversold', minval=1)

src = close
len = input.int(14, minval=1, title='Length')
up = ta.rma(math.max(ta.change(src), 0), len)
down = ta.rma(-math.min(ta.change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)

//Overbought
overbought = rsi >= inp_overbought ? color.new(color.green, 40) : na
overboughtcol = rsi >= inp_overbought ? color.rgb(156, 39, 176) : na
bgcolor(overbought)
//barcolor(overboughtcol)

//Oversold
oversold = rsi <= inp_oversold ? color.new(color.red, 40) : na
oversoldcol = rsi <= inp_oversold ? color.blue : na
bgcolor(oversold)
//barcolor(oversoldcol)