OPEN-SOURCE SCRIPT

MACD and RSI Strategy

71
//version=6
indicator("MACD and RSI Strategy", shorttitle="MACD_RSI", overlay=true)

// Các tham số của MACD
macdFastLength = input.int(12, title="MACD Fast Length")
macdSlowLength = input.int(26, title="MACD Slow Length")
macdSignalSmoothing = input.int(9, title="MACD Signal Length")

// Các tham số của RSI
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")

// Tính toán MACD
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalSmoothing)
macdHist = macdLine - signalLine

// Tính toán RSI
rsiValue = ta.rsi(close, rsiLength)

// Điều kiện mua
longCondition = ta.crossover(macdLine, signalLine) and rsiValue < rsiOversold

// Điều kiện bán
shortCondition = ta.crossunder(macdLine, signalLine) and rsiValue > rsiOverbought

// Tín hiệu mua/bán
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Vẽ các đường MACD và RSI
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
hline(0, "Zero Line", color=color.gray)
plot(rsiValue, color=color.purple, title="RSI", style=plot.style_line)
hline(rsiOverbought, "RSI Overbought", color=color.red, linestyle=hline.style_dotted)
hline(rsiOversold, "RSI Oversold", color=color.green, linestyle=hline.style_dotted)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.