OPEN-SOURCE SCRIPT

RSI + MACD Strategy with Alerts

//version=5
indicator("RSI + MACD Strategy with Alerts", overlay=true)

// ตั้งค่า RSI
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
rsiValue = ta.rsi(close, rsiLength)

// ตั้งค่า MACD
fastLength = input.int(12, title="MACD Fast Length")
slowLength = input.int(26, title="MACD Slow Length")
signalLength = input.int(9, title="MACD Signal Length")
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalLength)

// เงื่อนไขสัญญาณซื้อ (Buy Signal)
buyCondition = ta.crossover(macdLine, signalLine) and rsiValue < rsiOversold

// เงื่อนไขสัญญาณขาย (Sell Signal)
sellCondition = ta.crossunder(macdLine, signalLine) and rsiValue > rsiOverbought

// แสดงสัญญาณบนกราฟ
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// แจ้งเตือน (Alert)
alertcondition(buyCondition, title="Buy Alert", message="Buy Signal: RSI Oversold และ MACD Bullish Crossover")
alertcondition(sellCondition, title="Sell Alert", message="Sell Signal: RSI Overbought และ MACD Bearish Crossover")

Disclaimer