strategy · own pane · open source

ADX Trend Following

Deepwick · @deepwickv1Updated 2 Oct 2026▲ 0 users
Running…
Loading chart…

About

ADX/DMI trend following: long when ADX is above the trend threshold AND +DI is above -DI, exit when trend strength or direction collapses.

  • ADX > 25 = a trend worth riding; the higher the threshold, the stricter.
  • +DI > -DI confirms bullish direction.
  • Combine with a stop-loss or ATR trailing exit.

Source code

//@version=5
strategy("ADX Trend Following", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
len = input.int(14, "DI Length", minval=5, maxval=50, step=1)
threshold = input.int(25, "ADX Threshold", minval=5, maxval=100, step=1)
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
[plus, minus, adx] = ta.dmi(len, len)
longSignal = strategy.position_size == 0 and adx > threshold and plus > minus
exitSignal = strategy.position_size > 0 and (adx < threshold or plus < minus)
if longSignal
    strategy.entry("Long", strategy.long)
if strategy.position_size > 0
    strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
    strategy.close("Long", comment="Trend ended")
hline(25, "Threshold", color=color.gray, linestyle=hline.style_dashed)
p_ADX = plot(adx, "ADX", color=color.orange, linewidth=2)
p__DI = plot(plus, "+DI", color=color.green)
p__DI = plot(minus, "-DI", color=color.red)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=color.green, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=color.red, text="X")
alertcondition(longSignal, "ADX long entry", "ADX above threshold with +DI > -DI")
alertcondition(exitSignal, "ADX exit", "ADX trend ended")

Comments

No comments yet.

Sign in to comment.