The rules at a glance
- Market: any major pair on the 4-hour chart; the example uses AUDUSD
- Trend strength: ADX (14) above 25 and rising
- Direction: +DI above −DI and the price above the 50 EMA for a long (the mirror image for a short)
- Trigger: the candle where the ADX crosses above 25, or where +DI crosses above −DI while the ADX is already above 25; enter at its close
- Stop loss: 2 × ATR (14) from the entry
- Exit: when a candle closes back below the 50 EMA (above it for a short); there's no fixed target
- Size: risk 0.5% to 1% of the account on the 2 × ATR stop
What trend following means
A trend follower doesn't try to call tops or bottoms. They wait until a move is under way, join it, and stay in until it ends. That means accepting two things: you'll never buy the low, and many trades will be small losses when a promising move fizzles out. The system makes its money on the few trends that run a long way.
The rules below put that into practice on the 4-hour chart, where a trend can last days or weeks. The entry needs a strong trend, the stop is wide enough to survive normal pullbacks, and the exit waits for the trend to break rather than taking a fixed profit.
How the ADX works
The Average Directional Index (ADX) comes from J. Welles Wilder's 1978 book New Concepts in Technical Trading Systems, the same book that introduced the RSI and the ATR. It's built from three lines:
- +DI measures how much the highs are pushing up.
- −DI measures how much the lows are pushing down.
- ADX is a smoothed measure of the gap between them. It runs from 0 to 100 and shows how strong the trend is, not which way it's going.
| ADX reading | How traders commonly read it |
|---|---|
| Under 20 | Weak trend or a sideways market |
| 20 to 25 | A trend may be starting |
| Above 25 | A strong trend; this strategy's threshold |
| Rising | The trend is getting stronger |
| Falling from a high level | The trend is losing strength, even if the price still moves its way |
These levels are rules of thumb, not laws. Because the ADX is smoothed twice, it reacts late: by the time it crosses 25, the move has usually started. That's the trade-off of every trend filter.
The rules, step by step
1. Add the indicators
On a 4-hour chart, add a 50 EMA and TradingView's built-in DMI indicator with the default 14 and 14 settings. DMI shows the ADX and both DI lines in one pane.
2. Wait for a strong, rising trend
The ADX must be above 25 and higher than it was on the previous candle. For a long, +DI must be above −DI and the price above the 50 EMA. For a short, the opposite.
3. Enter on the trigger candle
Two things count as a trigger: the candle where the ADX crosses above 25, or the candle where +DI crosses above −DI while the ADX is already above 25. That keeps you from entering in the middle of a trend that's been running for weeks. Enter at the close.
4. Set the stop at 2 × ATR
The stop goes two times the 14-period ATR below the entry and stays there.
5. Exit when the price closes back below the 50 EMA
There's no target. Hold the trade until a candle closes below the 50 EMA (above it for a short), or until the stop is hit. One trade at a time.
Worked example: AUDUSD, 4-hour chart
50 EMA ADX +DI -DI
AUDUSD drifts sideways for weeks, with the ADX well under 25. Then the price starts to climb, +DI pulls away from −DI, and the ADX crosses above 25 at 25.1, with +DI at 26.4 and −DI at 6.5. The candle closes at 0.6624, above the 50 EMA at 0.6580. The ATR is 19 pips, so the stop goes 2 × 19 = 38 pips below the entry.
| AUDUSD long | |
|---|---|
| Entry | 0.6624 |
| Stop loss (2 × ATR) | 0.6586, 38 pips away |
| Account and risk | $10,000, risking 1% = $100 |
| Lot size | $100 ÷ (38 pips × $10) = 0.263, rounded down to 0.26 lots |
| Loss if the stop had been hit | $98.80 |
| Exit (close below the 50 EMA) | 0.6722, 66 candles later |
| Result | +98 pips, about 2.6R: $254.80 |
The trend carries AUDUSD as high as 0.6812 before a pullback closes below the 50 EMA. The exit gives back 90 pips from the top, which is what waiting for the trend to break costs. On AUDUSD one pip on one lot is $10, so the sum is simple; the lot size calculator handles any pair.
Why the exit is the 50 EMA, not a target
A fixed target would cap every winner, and trend following needs the occasional big winner to pay for the small losses. A close back through the 50 EMA is a simple sign the trend has at least paused. It gives back part of the move every time; a tighter exit gives back less but gets shaken out of more trends. If you'd rather trail a stop behind the price, the ATR trailing stop strategy does exactly that.
When ADX trend following struggles
- Sideways markets. The ADX can flick above 25 on a sharp move inside a range and fall straight back. Those trades usually end at a small loss on the 50 EMA exit.
- Late entries. Because the ADX lags, some signals arrive near the end of a move. The trigger rule helps but doesn't remove this.
- News spikes. One huge candle can push the ADX up without starting a trend. Check the economic calendar.
- Long losing streaks. Trend systems can go through months with few good trends. That's normal, and it's why the risk per trade has to stay small.
Risk management
- Size from the 2 × ATR stop. On the 4-hour chart that's often 30 to 50 pips on a major pair, which is about 0.2 to 0.33 lots at 1% of $10,000.
- Count correlated trades as one. A long AUDUSD and a long NZDUSD are nearly the same bet on the US dollar.
- Mind the swap. Holding for days costs or earns an overnight swap, which adds up on long trades.
- Weekend gaps can jump the stop. Size as if the loss could be a little bigger than planned.
Common mistakes
- Reading a high ADX as a buy signal. The ADX doesn't show direction. A strong downtrend has a high ADX too.
- Entering because the ADX is above 25 on any candle. The trigger rule exists so you don't buy late into an old trend.
- Taking profits early. Cutting the winners breaks the maths of trend following.
- Trading it on the 1-minute chart. The ADX's lag and the costs eat short-term trades. Test the timeframe first.
Backtest it yourself on TradingView
This page doesn't quote a win rate or a profit figure, and you should be wary of anyone who does without showing the test. Results change with the market, the dates, the data feed and the costs you put in. The honest way is to run the test yourself, and the free script below does the work in a couple of minutes.
- Open the chart. On TradingView, open AUDUSD on the 4-hour chart.
- Add the script. Open the Pine Editor from the Pine icon in the panel on the right of the chart (older layouts have it as a tab under the chart), delete the code that's already there, paste this strategy's code and click "Add to chart".
- Put in your costs. Open the strategy's settings and go to Properties. Enter your broker's commission and a little slippage. A test without costs flatters every strategy, and short-term ones most of all.
- Read the Strategy Tester. The panel under the chart shows the net profit, the maximum drawdown, the profit factor, the number of trades and a list of every trade. Click a few trades and check on the chart that each one follows the rules. Trade sizes are shown in units rather than lots: 100,000 units is one lot of a forex pair, and 100 ounces is one lot of gold.
- Change one setting at a time. Compare the ADX threshold (20, 25 and 30), the exit EMA (20, 50 and 100), the stop at 2 against 3 × ATR, and the 4-hour chart against the daily. Then run it on EURUSD, GBPUSD and USDJPY to see how much depends on the pair.
As a rough guide, don't trust a result with fewer than 100 trades, a profit factor under 1 once costs are in, or a drawdown you couldn't sit through with real money. Settings tuned to look good on one stretch of history often fail on the next, so check the same settings on dates you didn't tune them on, then demo trade the strategy for a few weeks. How much history you can test depends on your TradingView plan: the free plan loads 5,000 candles, which is a few months of 15-minute candles but years of daily ones.
The script sizes each trade from the stop loss and your risk percentage, starts with $10,000 and assumes 1:100 leverage (a 1% margin setting), so the tester doesn't flag margin calls on normal forex trade sizes. Change these under Properties to match your account. By default TradingView fills orders at the open of the candle after the signal, so the fill can differ a little from the signal candle's close.
Download the free Pine Script and PDF
The script is written in Pine Script version 6 for this guide and follows the rules above. It can't read the economic calendar, so skipping news days is up to you. It's free to use, change and share. The PDF is a one-page cheat sheet with the rules, how to read the ADX, a worked example and a checklist, to keep next to your chart.
Show the code (Pine Script v6, 64 lines)
//@version=6
// Trend Following (ADX) strategy by PipLedger (https://pipledgerfx.com/trend-following-strategy)
// Buys when the ADX shows a strong, strengthening trend with +DI above -DI and the price above the 50 EMA (sells the mirror image). Exits when a candle closes back through the 50 EMA, with a 2 x ATR stop as protection.
// Free to use and change. For education and backtesting only; not financial advice.
strategy("PipLedger: Trend Following (ADX)", shorttitle="ADX Trend", overlay=true, initial_capital=10000, pyramiding=0, default_qty_type=strategy.fixed, default_qty_value=1, margin_long=1, margin_short=1, currency=currency.USD)
// ---------- Inputs
diLen = input.int(14, "DI length", minval=2)
adxLen = input.int(14, "ADX smoothing", minval=2)
adxMin = input.float(25.0, "ADX must be above", minval=5.0, step=1.0)
emaLen = input.int(50, "Trend EMA length (entry filter and exit)", minval=5)
atrLen = input.int(14, "ATR length", minval=2)
stopMult = input.float(2.0, "Stop loss (x ATR)", minval=0.5, step=0.25)
riskPct = input.float(1.0, "Risk per trade (% of equity)", minval=0.1, maxval=5.0, step=0.1)
// ---------- Helpers
fx = strategy.convert_to_account(1.0) // one unit of the chart's quote currency in account currency (1 on USD-quoted charts)
calcQty(float entry, float stop) =>
float dist = math.abs(entry - stop)
dist > 0 and not na(fx) ? strategy.equity * riskPct / 100 / (dist * syminfo.pointvalue * fx) : 0.0
[diPlus, diMinus, adx] = ta.dmi(diLen, adxLen)
ema = ta.ema(close, emaLen)
atr = ta.atr(atrLen)
rising = adx > adx[1]
// the trigger: ADX crosses above the threshold, or the DI lines cross while the ADX is already above it
// (the crosses are worked out on every candle first: Pine v6 skips the right side of "and"/"or" when it can)
adxUp = ta.crossover(adx, adxMin)
diUp = ta.crossover(diPlus, diMinus)
diDn = ta.crossunder(diPlus, diMinus)
upTrig = adxUp or (diUp and adx > adxMin)
dnTrig = adxUp or (diDn and adx > adxMin)
// ---------- Exits first: a close back through the EMA ends the trend trade
if strategy.position_size > 0 and close < ema
strategy.close("Long", comment="Close below EMA")
if strategy.position_size < 0 and close > ema
strategy.close("Short", comment="Close above EMA")
// ---------- Entries, one position at a time
flat = strategy.position_size == 0
longSig = flat and upTrig and rising and adx > adxMin and diPlus > diMinus and close > ema
shortSig = flat and dnTrig and rising and adx > adxMin and diMinus > diPlus and close < ema
if longSig
float sl = close - stopMult * atr
float q = calcQty(close, sl)
if q > 0
strategy.entry("Long", strategy.long, qty=q)
strategy.exit("Long stop", "Long", stop=sl)
if shortSig
float sl = close + stopMult * atr
float q = calcQty(close, sl)
if q > 0
strategy.entry("Short", strategy.short, qty=q)
strategy.exit("Short stop", "Short", stop=sl)
// ---------- Chart (the ADX itself is best viewed with TradingView's built-in DMI indicator in its own pane)
plot(ema, "50 EMA", color=color.new(color.orange, 0), linewidth=2)
bgcolor(adx > adxMin and diPlus > diMinus ? color.new(color.teal, 93) : adx > adxMin and diMinus > diPlus ? color.new(color.red, 93) : na, title="Strong trend (ADX above threshold)")
plotshape(longSig, "Long", shape.triangleup, location.belowbar, color.teal, size=size.small)
plotshape(shortSig, "Short", shape.triangledown, location.abovebar, color.red, size=size.small)Trading this from India
Residents can trade EURUSD, GBPUSD and USDJPY futures and options on NSE and BSE through a SEBI-registered broker. The contracts are quoted the same way as the spot pair, one lot is 1,000 units of the base currency, and they're cash-settled in rupees. They trade only from 9 a.m. to 7:30 p.m. IST, volumes are thin and not every broker offers them, so check the hours and the spread first. AUDUSD isn't one of those contracts, so if you want to trade these rules on an Indian exchange, test them on EURUSD, GBPUSD or USDJPY. Trading forex or CFDs with offshore online platforms isn't allowed for residents under FEMA, even if the app is easy to download. Details are in is forex trading legal in India.
Related strategies: 20 and 50 EMA pullback, ATR trailing stop, EMA and RSI(2), RSI divergence, 9 and 21 EMA crossover, MACD and 200 EMA, RSI 60/40. All 34 strategies are compared on one page in forex trading strategies.