//@version=5 indicator(shorttitle="BB-StochRSI with EMA and Engulfing", title="BB-StochRSI with EMA, BB Extremes, and Engulfing", overlay=true) // General Inputs src = input.source(close, title="Source") offset = input.int(0, title="Offset", minval=-500, maxval=500) // Bollinger Band Inputs bb_length = input.int(20, title="Bollinger Band Length") bb_mult = input.float(2.0, title="StdDev") // Bollinger Band Calculation bb_basis = ta.sma(src, bb_length) bb_dev = bb_mult * ta.stdev(src, bb_length) bb_upper = bb_basis + bb_dev bb_lower = bb_basis - bb_dev plot(bb_basis, "BB Basis", color=color.maroon, offset=offset) plot(bb_upper, "BB Upper", color=color.teal, offset=offset) plot(bb_lower, "BB Lower", color=color.teal, offset=offset) fill(plot(bb_upper), plot(bb_lower), color=color.new(color.aqua, 95), title="BB Background") // Exponential Moving Averages (EMAs) ema20 = ta.ema(src, 20) ema200 = ta.ema(src, 200) plot(ema20, "EMA 20", color=color.orange, linewidth=1, offset=offset) plot(ema200, "EMA 200", color=color.blue, linewidth=1, offset=offset) // Stochastic RSI Inputs stoch_lengthRSI = input.int(14, title="RSI Length") stoch_length = input.int(14, title="Stochastic Length") stoch_smoothK = input.int(3, title="K Smoothing") stoch_smoothD = input.int(3, title="D Smoothing") // Stochastic RSI Calculation rsi = ta.rsi(src, stoch_lengthRSI) k = ta.sma(ta.stoch(rsi, rsi, rsi, stoch_length), stoch_smoothK) d = ta.sma(k, stoch_smoothD) stoch_upperlimit = input.float(90, "Upper Limit") stoch_lowerlimit = input.float(10, "Lower Limit") // BB-StochRSI Extreme Conditions Bull_BB_Extreme = close[1] < bb_lower[1] and close > bb_lower and k[1] < stoch_lowerlimit and d[1] < stoch_lowerlimit Bear_BB_Extreme = close[1] > bb_upper[1] and close < bb_upper and k[1] > stoch_upperlimit and d[1] > stoch_upperlimit // Engulfing Conditions is_bullish_engulfing = open[3] > close[3] and open[2] > close[2] and open[1] > close[1] and close > open and (close >= open[1] or close[1] >= open) and close - open > open[1] - close[1] is_bearish_engulfing = open[3] < close[3] and open[2] < close[2] and close[1] > open[1] and open > close and (open >= close[1] or open[1] >= close) and open - close > close[1] - open[1] // Check EMA 200 Conditions for Buys and Sells Buy_Condition = is_bullish_engulfing and close > ema200 Sell_Condition = is_bearish_engulfing and close < ema200 // Plot Engulfing Signals plotshape(is_bullish_engulfing, style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.small, title="Bullish Engulfing") plotshape(is_bearish_engulfing, style=shape.triangledown, location=location.abovebar, color=color.maroon, size=size.small, title="Bearish Engulfing") // ATR Calculation for Stop Loss and Take Profit atr_length = input.int(14, title="ATR Length") atr = ta.atr(atr_length) // Calculate Stop Loss and Take Profit Levels long_stop_loss = close - 3 * atr long_take_profit = close + 2 * atr short_stop_loss = close + 3 * atr short_take_profit = close - 2 * atr // Plot Buy and Sell Conditions plotshape(Buy_Condition, style=shape.triangleup, location=location.belowbar, color=color.blue, size=size.small, title="Buy Signal") plotshape(Sell_Condition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal") // Plot Stop Loss and Take Profit Levels plot(Buy_Condition ? long_stop_loss : na, "Long Stop Loss", color=color.red, linewidth=1, offset=offset) plot(Buy_Condition ? long_take_profit : na, "Long Take Profit", color=color.green, linewidth=1, offset=offset) plot(Sell_Condition ? short_stop_loss : na, "Short Stop Loss", color=color.red, linewidth=1, offset=offset) plot(Sell_Condition ? short_take_profit : na, "Short Take Profit", color=color.green, linewidth=1, offset=offset) // Alert Conditions alertcondition(Buy_Condition, title="Buy Signal", message="Buy Signal: 3 Bullish Engulfing Candles above 200 EMA") alertcondition(Sell_Condition, title="Sell Signal", message="Sell Signal: 3 Bearish Engulfing Candles below 200 EMA")