OPEN-SOURCE SCRIPT

Sirilak Heikin Ashi + RSI Crossover Strategy (Chart)

300
//version=5
indicator("Sirilak Heikin Ashi + RSI Crossover Strategy (Chart)", overlay=true)

// Heikin Ashi Calculations
var float haClose = na
var float haOpen = na
var float haHigh = na
var float haLow = na

haClose := (open + high + low + close) / 4
haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
haHigh := math.max(high, math.max(haOpen, haClose))
haLow := math.min(low, math.min(haOpen, haClose))

// Heikin Ashi Color Logic
isGreen = haClose > haOpen // Green candle
isRed = haClose < haOpen // Red candle

// RSI Calculations
rsiLength = input.int(5, title="RSI Length")
rsiSmaLength = input.int(21, title="RSI SMA Length")
rsiValue = ta.rsi(close, rsiLength)
rsiSma = ta.sma(rsiValue, rsiSmaLength)

// RSI Crossover Logic
rsiCrossAbove = ta.crossover(rsiValue, rsiSma) // RSI crosses above its SMA
rsiCrossBelow = ta.crossunder(rsiValue, rsiSma) // RSI crosses below its SMA

// Buy Signal (Entry) - After Candle Close
buySignal = isGreen and rsiCrossAbove and barstate.isconfirmed

// Buy Exit (Close) - After Candle Close
buyExit = isRed and rsiCrossBelow and barstate.isconfirmed

// Sell Signal (Entry) - After Candle Close
sellSignal = isRed and rsiCrossBelow and barstate.isconfirmed

// Sell Exit (Close) - After Candle Close
sellExit = isGreen and rsiCrossAbove and barstate.isconfirmed

// Plot Heikin Ashi Candles on the Main Chart
candleColor = isGreen ? color.green : color.red
plotcandle(haOpen, haHigh, haLow, haClose, color=candleColor)

// Plot Buy Entry Signal (Green Label Below Candle)
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", size=size.small, offset=0)

// Plot Buy Exit Signal (Yellow Label Above Candle)
plotshape(series=buyExit, location=location.abovebar, color=color.yellow, style=shape.labeldown, text="BUY EXIT", size=size.small, offset=0)

// Plot Sell Entry Signal (Red Label Above Candle)
plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", size=size.small, offset=0)

// Plot Sell Exit Signal (Black Label Below Candle)
plotshape(series=sellExit, location=location.belowbar, color=color.black, style=shape.labelup, text="SELL EXIT", size=size.small, offset=0)

// Alerts (Triggered Only After Candle Close)
if (buySignal)
alert("BUY: Heikin Ashi Green + RSI Cross Above SMA", alert.freq_once_per_bar_close)

if (buyExit)
alert("BUY EXIT: Heikin Ashi Red + RSI Cross Below SMA", alert.freq_once_per_bar_close)

if (sellSignal)
alert("SELL: Heikin Ashi Red + RSI Cross Below SMA", alert.freq_once_per_bar_close)

if (sellExit)
alert("SELL EXIT: Heikin Ashi Green + RSI Cross Above SMA", alert.freq_once_per_bar_close)

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.