Pinescript Indicator
Pinescript Indicator
// 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 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")