OPEN-SOURCE SCRIPT

SIRILAK BOT RSI with SMA Cross Signals + Heikin Ashi

110
//version=5
indicator("SIRILAK BOT RSI with SMA Cross Signals + Heikin Ashi", overlay=true)

// RSI and SMA settings
rsiLength = 5
smaLength = 21

// Heikin Ashi calculations
var float heikinOpen = na
heikinClose = (open + high + low + close) / 4
heikinOpen := na(heikinOpen[1]) ? (open + close) / 2 : (heikinOpen[1] + heikinClose[1]) / 2
heikinHigh = math.max(high, math.max(heikinOpen, heikinClose))
heikinLow = math.min(low, math.min(heikinOpen, heikinClose))

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

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.