//@version=5
indicator("Multi-Purpose Technical Indicator", shorttitle="MPTI", overlay=true)
// Input parameters
ma_length = input.int(20, title="Moving Average Length", minval=1)
rsi_length = input.int(14, title="RSI Length", minval=1)
bb_length = input.int(20, title="Bollinger Bands Length", minval=1)
bb_mult = input.float(2.0, title="Bollinger Bands Multiplier", minval=0.1)
show_ma = input.bool(true, title="Show Moving Average")
show_bb = input.bool(true, title="Show Bollinger Bands")
show_signals = input.bool(true, title="Show Buy/Sell Signals")
show_rsi_levels = input.bool(true, title="Show RSI Overbought/Oversold")
// Color inputs
ma_color = input.color(color.blue, title="Moving Average Color")
bb_upper_color = input.color(color.red, title="BB Upper Band Color")
bb_lower_color = input.color(color.green, title="BB Lower Band Color")
buy_color = input.color(color.lime, title="Buy Signal Color")
sell_color = input.color(color.red, title="Sell Signal Color")
// Calculate indicators
sma = ta.sma(close, ma_length)
rsi = ta.rsi(close, rsi_length)
// Bollinger Bands
bb_basis = ta.sma(close, bb_length)
bb_dev = bb_mult * ta.stdev(close, bb_length)
bb_upper = bb_basis + bb_dev
bb_lower = bb_basis - bb_dev
// Signal conditions
ma_bullish = close > sma and close[1] <= sma[1]
ma_bearish = close < sma and close[1] >= sma[1]
rsi_oversold = rsi < 30
rsi_overbought = rsi > 70
bb_squeeze = (bb_upper - bb_lower) / bb_basis < 0.1
// Buy/Sell signals
buy_signal = ma_bullish and rsi_oversold and not bb_squeeze
sell_signal = ma_bearish and rsi_overbought and not bb_squeeze
// Plot Moving Average
plot(show_ma ? sma : na, title="SMA", color=ma_color, linewidth=2)
// Plot Bollinger Bands
upper_band = plot(show_bb ? bb_upper : na, title="BB Upper", color=bb_upper_color,
linewidth=1)
lower_band = plot(show_bb ? bb_lower : na, title="BB Lower", color=bb_lower_color,
linewidth=1)
fill(upper_band, lower_band, color=color.new(color.gray, 95), title="BB Fill")
// Plot signals
plotshape(show_signals and buy_signal, title="Buy Signal", style=shape.labelup,
location=location.belowbar, color=buy_color, textcolor=color.white,
size=size.small, text="BUY")
plotshape(show_signals and sell_signal, title="Sell Signal", style=shape.labeldown,
location=location.abovebar, color=sell_color, textcolor=color.white,
size=size.small, text="SELL")
// Background coloring for RSI levels
bgcolor(show_rsi_levels and rsi_overbought ? color.new(color.red, 90) : na,
title="RSI Overbought BG")
bgcolor(show_rsi_levels and rsi_oversold ? color.new(color.green, 90) : na,
title="RSI Oversold BG")
// Alert conditions
alertcondition(buy_signal, title="Buy Alert", message="Buy signal detected: Price
above MA, RSI oversold")
alertcondition(sell_signal, title="Sell Alert", message="Sell signal detected:
Price below MA, RSI overbought")
alertcondition(bb_squeeze, title="BB Squeeze Alert", message="Bollinger Bands
squeeze detected - potential breakout coming")
// Table for current values
if barstate.islast
var table info_table = table.new(position.top_right, 2, 6, bgcolor=color.white,
border_width=1)
table.cell(info_table, 0, 0, "Indicator", text_color=color.black,
text_size=size.small)
table.cell(info_table, 1, 0, "Value", text_color=color.black,
text_size=size.small)
table.cell(info_table, 0, 1, "Price", text_color=color.black,
text_size=size.small)
table.cell(info_table, 1, 1, str.tostring(close, "#.##"),
text_color=color.black, text_size=size.small)
table.cell(info_table, 0, 2, "SMA(" + str.tostring(ma_length) + ")",
text_color=color.black, text_size=size.small)
table.cell(info_table, 1, 2, str.tostring(sma, "#.##"), text_color=color.black,
text_size=size.small)
table.cell(info_table, 0, 3, "RSI(" + str.tostring(rsi_length) + ")",
text_color=color.black, text_size=size.small)
table.cell(info_table, 1, 3, str.tostring(rsi, "#.##"), text_color=rsi > 70 ?
color.red : rsi < 30 ? color.green : color.black, text_size=size.small)
table.cell(info_table, 0, 4, "BB Upper", text_color=color.black,
text_size=size.small)
table.cell(info_table, 1, 4, str.tostring(bb_upper, "#.##"),
text_color=color.black, text_size=size.small)
table.cell(info_table, 0, 5, "BB Lower", text_color=color.black,
text_size=size.small)
table.cell(info_table, 1, 5, str.tostring(bb_lower, "#.##"),
text_color=color.black, text_size=size.small)