// Define Short-term and Long-term MAs shortTermMA = ta.sma(close, 9) longTermMA = ta.sma(close, 21)
// Define RSI rsi = ta.rsi(close, 14)
// Define Volume volumeMA = ta.sma(volume, 20)
// Define Buy and Sell Conditions based on MA Crossovers, RSI, and Volume buyCondition = ta.crossover(shortTermMA, longTermMA) and rsi < 30 and volume > volumeMA sellCondition = ta.crossunder(shortTermMA, longTermMA) and rsi > 70 and volume > volumeMA
// Detect Bullish Engulfing Pattern bullishEngulfing = (open[1] > close[1]) and (close > open) and (close > high[1]) and (open < low[1])
// Detect Bearish Engulfing Pattern bearishEngulfing = (open[1] < close[1]) and (close < open) and (close < low[1]) and (open > high[1])
// Combine all Buy and Sell Conditions finalBuyCondition = buyCondition or bullishEngulfing finalSellCondition = sellCondition or bearishEngulfing
// Plot Short-term and Long-term MA plot(shortTermMA, "Short Term MA", color=color.blue, linewidth=2) plot(longTermMA, "Long Term MA", color=color.red, linewidth=2)