PipLedger
Today's forex newsNFP, CPI, FOMC and other high-impact eventsEconomic calendarCalendar →

Trend following strategy: ADX and 50 EMA rules, with a free Pine Script

Trend following is simple to describe: buy what's going up, sell what's going down, cut the losers quickly and let the winners run. The hard part is telling a real trend from noise. This strategy uses the ADX to measure trend strength and the 50 EMA to set the direction and the exit. Here are the exact rules, how the ADX works, a worked AUDUSD example with the lot size and a free TradingView script.

By M. A. Horaira. Updated 10 October 2026. 11 minute read.

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:

ADX readingHow traders commonly read it
Under 20Weak trend or a sideways market
20 to 25A trend may be starting
Above 25A strong trend; this strategy's threshold
RisingThe trend is getting stronger
Falling from a high levelThe 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

Entry 0.6624Stop 0.6586ADX crosses 25Close below the 50 EMA: exit25ADX above 25ADX, +DI and -DI (14)

50 EMA ADX +DI -DI

Illustrative chart drawn for this guide to show the rules. It isn't a real day's prices. AUDUSD, 4-hour candles, with the ADX and DI lines below.

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
Entry0.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

Risk management

Common mistakes

  1. Reading a high ADX as a buy signal. The ADX doesn't show direction. A strong downtrend has a high ADX too.
  2. Entering because the ADX is above 25 on any candle. The trigger rule exists so you don't buy late into an old trend.
  3. Taking profits early. Cutting the winners breaks the maths of trend following.
  4. 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.

  1. Open the chart. On TradingView, open AUDUSD on the 4-hour chart.
  2. 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".
  3. 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.
  4. 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.
  5. 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.

Quick answers

What is a trend following strategy?

It's a strategy that joins a move once it's under way and stays in until it ends, instead of trying to predict turns. Most trend following systems have many small losses and a few large wins, so they need a stop on every trade and no cap on the winners.

What is the ADX indicator?

The Average Directional Index measures how strong a trend is on a scale of 0 to 100. It was introduced by J. Welles Wilder in 1978, together with the +DI and −DI lines, which show the direction. A high ADX means a strong trend, up or down.

What ADX value means a strong trend?

A common rule of thumb is that an ADX above 25 means a strong trend and below 20 a weak or sideways market. This strategy uses 25 and also needs the ADX to be rising.

Which timeframe is best for trend following in forex?

This strategy uses the 4-hour chart, which gives fewer signals, usually held for days. The daily chart gives fewer, longer trades. Lower timeframes give more signals, but the ADX's lag and trading costs matter more.

Does the ADX show the direction of the trend?

No. The ADX only shows strength. The direction comes from the +DI and −DI lines (or the price against a moving average): +DI above −DI points up, −DI above +DI points down.

Why doesn't this strategy use a profit target?

Trend following relies on a few large winners to pay for many small losses. A fixed target would cut those winners short, so the trade is held until the price closes back through the 50 EMA or hits the stop.

More guides

All 75 guides →

हिंदी में पढ़ें: Lot size kaise nikale?, Prop firm challenge kaise pass kare?, Gold trading kaise kare?, Forex trading kya hai, और India में यह legal है या नहीं?

Trading psychology

The habits that decide whether a good strategy makes money.

All 14 trading psychology guides

8 popular prop firms

Well-known firms for forex, gold and index traders that were still operating in 2026. Compare their rules before you buy a challenge.

If a link in this list is a referral link, PipLedger may earn a commission if you sign up, at no extra cost to you. This list is not a recommendation. Programs, prices and rules change often, so check each firm's own site, including its margin and drawdown rules, before you buy a challenge.