OPEN-SOURCE SCRIPT

ADX +DI/-DI with Buy/Sell Signals

59
//version=5
indicator("ADX +DI/-DI with Buy/Sell Signals", overlay=true)

// Inputs
adxLength = input.int(14, "ADX Length")
threshold = input.float(25.0, "ADX Threshold")

// Directional Movement
upMove = ta.change(high)
downMove = -ta.change(low)
plusDM = (upMove > downMove and upMove > 0) ? upMove : 0.0
minusDM = (downMove > upMove and downMove > 0) ? downMove : 0.0

// True Range and Smoothed Values
tr = ta.rma(ta.tr, adxLength)
plusDI = 100 * ta.rma(plusDM, adxLength) / tr
minusDI = 100 * ta.rma(minusDM, adxLength) / tr
dx = 100 * math.abs(plusDI - minusDI) / (plusDI + minusDI)
adx = ta.rma(dx, adxLength)

// Buy/Sell Conditions
buySignal = ta.crossover(plusDI, minusDI) and adx > threshold
sellSignal = ta.crossover(minusDI, plusDI) and adx > threshold

// Plot Buy/Sell markers
plotshape(buySignal, title="BUY", location=location.belowbar,
color=color.new(color.lime, 0), style=shape.triangleup, size=size.large, text="BUY")
plotshape(sellSignal, title="SELL", location=location.abovebar,
color=color.new(color.red, 0), style=shape.triangledown, size=size.large, text="SELL")

// Optional ADX + DI lines (hidden by default)
plot(adx, title="ADX", color=color.yellow, linewidth=2, display=display.none)
plot(plusDI, title="+DI", color=color.green, display=display.none)
plot(minusDI, title="-DI", color=color.red, display=display.none)
hline(threshold, "ADX Threshold", color=color.gray, linestyle=hline.style_dotted)

// Alerts
alertcondition(buySignal, title="BUY Alert", message="ADX Buy Signal Triggered")
alertcondition(sellSignal, title="SELL Alert", message="ADX Sell Signal Triggered")

Wyłączenie odpowiedzialności

Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.