OPEN-SOURCE SCRIPT

EMA Crossover with RSI & ADX

89
//version=5
indicator("EMA Crossover with RSI & ADX", overlay=true)

// Input parameters
fastLength = input(9, title="Fast EMA Length")
slowLength = input(21, title="Slow EMA Length")
rsiLength = input(14, title="RSI Length")
adxLength = input(14, title="ADX Length")

// Calculate EMAs
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)

// Calculate RSI
rsi = ta.rsi(close, rsiLength)

// Calculate ADX manually
upMove = high - ta.highest(high[1], 1)
downMove = ta.lowest(low[1], 1) - low
plusDM = upMove > downMove and upMove > 0 ? upMove : 0
minusDM = downMove > upMove and downMove > 0 ? downMove : 0
tr = ta.rma(ta.tr, adxLength)
plusDI = ta.rma(plusDM, adxLength) / tr * 100
minusDI = ta.rma(minusDM, adxLength) / tr * 100
dx = math.abs(plusDI - minusDI) / (plusDI + minusDI) * 100
adx = ta.rma(dx, adxLength)

// Crossover conditions
bullishCross = ta.crossover(fastEMA, slowEMA) and rsi > 50 and adx > 20
bearishCross = ta.crossunder(fastEMA, slowEMA) and rsi < 50 and adx > 20

// Plot EMAs
plot(fastEMA, title="Fast EMA", color=color.blue)
plot(slowEMA, title="Slow EMA", color=color.red)

// Buy/Sell signals
plotshape(bullishCross, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(bearishCross, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")

// Plot RSI & ADX in a separate window
hline(50, "RSI 50 Level", color=color.gray)
plot(rsi, title="RSI", color=color.purple)
plot(adx, title="ADX", color=color.orange)

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน