// Plot Heikin Ashi candles on the price chart plotcandle(open=heikinOpen, high=heikinHigh, low=heikinLow, close=heikinClose, color=heikinClose >= heikinOpen ? color.green : color.red, wickcolor=color.black, title="Heikin Ashi Candles")
// Calculate RSI and SMA rsi = ta.rsi(close, rsiLength) sma = ta.sma(rsi, smaLength)
// Conditions for buy and sell signals sellSignal = ta.crossover(sma, rsi) // RSI crosses below SMA buySignal = ta.crossunder(sma, rsi) // RSI crosses above SMA
// Track the last signal var string lastSignal = ""
// Ensure signal is only given after the candle closes sellSignalClose = barstate.isconfirmed and sellSignal and (lastSignal != "SELL") // Confirm signal only on completed bar, and must be different from previous signal buySignalClose = barstate.isconfirmed and buySignal and (lastSignal != "BUY") // Confirm signal only on completed bar, and must be different from previous signal
// Update the last signal if (buySignalClose) lastSignal := "BUY" if (sellSignalClose) lastSignal := "SELL"
// Plot RSI and SMA on RSI pane plot(rsi, color=color.blue, linewidth=2, title="RSI") plot(sma, color=color.orange, linewidth=2, title="SMA")
// Plot buy and sell signals only when the candle closes plotshape(series=sellSignalClose, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL") plotshape(series=buySignalClose, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY")