Skip to content

MetaTrader 5

Trend Following Strategy: Rules, Profile and Alert Mapping

A trend following strategy holds a position in the direction of a measured price move and exits when a stated rule says the move has ended. Typical entries are a breakout above a prior N-bar high or a close above a moving average. Typical exits are an opposite breakout or a trailing stop. The rules decide nothing about whether a trend will continue; a test on your market and costs has to answer that.

Illustrative cover for trend following rules, showing an abstract rising price path with a stepped trailing line beneath it, with the official PineConnector logo.
Trend following rules enter with a measured move and exit when a trailing rule is hit. Illustrative.

This page is part of PineConnector's trading strategy library, which compares trend following with mean reversion, breakout and other families. Every rule below is an illustrative example to test, not a recommendation.

Trend following at a glance

Scroll horizontally to read every column.

Item Trend following as a rule
Behaviour it expects A move that has started continues for long enough to pay for the losing entries.
Common entry rules Close above the prior N-bar highest high (a Donchian breakout), or close above an N-bar moving average.
Common exit rules Close below a shorter M-bar lowest low, a trailing stop, or the opposite moving-average condition.
Typical profile Many small losses and fewer, larger wins. Researchers describe trend-following returns as positively skewed.
What breaks it Sideways ranges that reverse soon after each entry, and costs paid on every one of those reversals.

Moskowitz, Ooi and Pedersen call the academic version time-series momentum. It "focuses purely on a security’s own past return", unlike cross-sectional momentum, which ranks securities against each other.[1] Trend following in this page means the time-series kind: one instrument, judged against its own history.

What are the rules of a trend following strategy?

A complete trend-following rule set answers five questions: how the trend is measured, when to enter, where the initial stop sits, how the exit follows the move, and how much to trade. Each answer needs a lookback, a comparison and an evaluation time.

Measure the trend: channel or moving average

Richard Donchian's channel is the classic breakout measure. TradingView's help page gives the formula with a 20-day example and describes Donchian as "The Father of Trend Following".[2]

Upper channel = highest high of the prior N bars; lower channel = lowest low of the prior N bars

This page uses the prior N bars, excluding the bar being tested. Including the current bar makes “close above the upper channel” impossible, because the current high is part of the maximum.

A moving-average regime is the other common measure: the trend is up while the close is above an N-bar simple moving average (SMA) or exponential moving average (EMA). An earlier PineConnector trend trading guide used a close above a 50-day moving average as its example. Treat that as a definition to test, not as evidence that an uptrend exists. The moving average crossover rules page covers SMA and EMA formulas and exact crossing tests.

Enter, stop, trail and exit

  • Entry: on the closed bar, the close is above the upper channel (long) or below the lower channel (short). A pullback variant waits for a retracement toward the average after the regime turns up.
  • Initial stop: a price that defines the initial risk, R. A common choice is the lowest low of a shorter M-bar window, which sits below recent support.
  • Trailing exit: the M-bar lowest low rises with the trend and never loosens. A close below it ends the trade.
  • Size: a fixed size, or a size set from the stop distance. The position sizing methods guide covers both.

Choosing M shorter than N makes exits react before entries do. Neither value is a setting this page recommends.

Why does trend following have many small losses and a few large wins?

The profile follows from the exit rule. A loser is cut at the initial stop, usually near 1R. A winner stays open until the trail is hit, so its size is set by how far the market moved, not by a fixed target. Lempérière and co-authors found that "trend following has both positive skewness and positive excess returns" in their sample, unlike the risk-premium strategies they studied.[3] In a 2026 preprint, Sepp and Lucic derive the closed-form skewness of aggregated trend-following returns under white noise and report that it "is positive at every horizon".[4]

Positive skew describes the shape of results, not their sign. The return figures in those papers come from their own samples and are not repeated here. A reader's rule on a reader's market can still lose money.

The shape changes what the rule needs to break even. Using the house break-even formula, a rule whose average win is 3R and average loss is 1R breaks even before costs at:

Break-even win rate = AL / (AW + AL) = 1 / (3 + 1) = 25%

PineConnector's Analytics guide gives the same before-costs relationship as 1 ÷ (1 + reward-to-risk).[15] Add a cost of 0.1R per trade and the formula becomes (AL + c) / (AW + AL) = 1.1 / 4 = 27.5%. These are illustrative inputs, not results of any strategy. The break-even win rate guide explains the formula.

Long runs of small losses are the normal cost of this shape, which is why a trend rule can look broken for months while behaving as designed. The losing streak probability page shows how often long streaks occur by chance.

Worked example: a channel breakout with a trailing exit

Illustrative prices and lookbacks, not a recommendation. Take EURUSD on a chart with N = 20 and M = 10 bars. One PineConnector pip on a five-decimal quote is 0.00010.[8]

Step Illustrative values Result
Entry test Prior 20-bar high 1.10500; closed bar's close 1.10600 1.10600 > 1.10500, so the long condition is true
Initial stop Prior 10-bar low 1.10000 Risk = 1.10600 − 1.10000 = 0.00600, or 60 pips = 1R
Trail Later, the 10-bar low has risen to 1.11900 The exit level is now 1.11900
Exit test A bar closes at 1.11800 1.11800 < 1.11900, so the exit condition is true
Result if filled at that close 1.11800 − 1.10600 = 0.01200 120 pips ÷ 60 pips = +2R before costs

The same rule loses 1R if the next bars close back below 1.10000 first, before costs and assuming the stop fills at its level. Neither path says how often each happens. A backtest over enough trades has to show that, and the backtesting guide covers costs and out-of-sample checks.

Illustrative trend following diagram: a close above the prior 20-bar high opens a long, the 10-bar low trails upward as a stop, and a close below it ends the trade.
Illustrative lookbacks and prices, not recommended settings. The trail is a rule; whether it sits in the strategy or at the broker is a separate choice.

How does a trend rule become TradingView alerts and MT5 orders?

A TradingView strategy "executes strictly once per closed bar" unless its settings say otherwise.[5] Alerts, however, trigger only on realtime bars, and an alert can fire before the bar closes unless its frequency is set to once per bar close.[6][7] For a close-based channel rule, evaluate on the closed bar and record which alert frequency you chose.

Rule element TradingView side MT5 side
Entry condition Close above the prior N-bar high, on the bar close An entry message such as buy with a volume and a stop
Initial stop The M-bar low when the entry fires A broker-side stop only if the message requests one
Trailing exit The rising M-bar low; a close below it Either a close message on the exit alert, or a stop moved by a modification message

The difference in the last row matters. PineConnector's converter guide states that the integration does not place a script's simulated stops and targets as protective broker orders.[11] A stop that exists only in Pine closes the position only if the exit alert triggers, is delivered and is processed. A broker-side stop sits in MT5 whether or not the next alert arrives.

Verify on a demo account first. Follow PineConnector's demo testing guide; a successful demo order verifies the tested setup, not that the strategy will be profitable.[12] Choose your own symbol, size and rules. The examples below are illustrative messages for the TradingView alert's Message field, not an instruction to trade:

LicenseID,buy,EURUSD,vol_lots=0.01,sl_pips=60,comment=TF-A
LicenseID,newsltplong,EURUSD,sl_price=1.11900
LicenseID,closelong,EURUSD,comment=TF-A

The first requests a 0.01-lot buy with a stop 60 PineConnector pips from entry, labelled TF-A. The format is LicenseID, command, symbol, parameters, with one command and one symbol per message.[8] The second asks the EA to change the stop on matching EURUSD buys to 1.11900; the modification reference says it does not change entry or volume, and broker constraints apply.[9] Comment filtering is documented for closes and cancellations, not for this modification, so check which buys it reaches. The third requests closing only EURUSD buys carrying the TF-A comment.[16]

PineConnector also documents pip trailing with trailtrig=, traildist= and trailstep= on the entry message.[10] Those parameters trail a fixed pip distance behind price. A channel trail follows an M-bar low instead, so the two are different rules and will exit at different prices. Pick one and test that one.

Each stage is a separate event: the condition becomes true, the alert triggers, the webhook is delivered, PineConnector processes the signal, the EA sends an order request, and the broker accepts it and fills a deal that becomes a position. MetaQuotes distinguishes the order, the deal and the position.[13] For exits managed after entry, see automating exits, breakeven and trailing stops.

What breaks a trend following strategy?

  • Ranges and whipsaws. In a sideways market, each breakout reverses soon after entry, and each reversal is a small loss plus costs. The old version of this page claimed trend following adapts to ranging markets; the rule itself has no such property.
  • Costs and slippage. Breakout entries and stop exits often happen when price is moving. TradingView calls slippage "dynamic and unpredictable" and suggests applying a fixed amount in tests.[5] Automation does not remove slippage.
  • Gaps. When price gaps past a stop, TradingView's emulator fills at the next bar's open rather than at the stop level.[5] Broker stops can fill beyond their level too. See weekend gaps at the market open.
  • Over-optimisation. Trying many N and M values on one history and keeping the best fits noise. TradingView warns an overfit strategy "often fails to perform well on new, unseen data".[5] The overfitting guide covers the checks.
  • Regime change. A rule tuned on a trending period can meet years of ranges. Test across periods and markets rather than one favourable stretch.
  • Data differences. TradingView and the broker can quote different prices, so a channel level on one may not match the other.[14]

Drawdown and risk-adjusted measures such as the Sharpe and Sortino ratios describe a tested rule's path; they do not make a rule work. The trading performance metrics hub explains them.

Frequently asked questions

What are trend following trading rules?

Trend following trading rules define how a trend is measured, when to enter, where the initial stop sits and how the exit follows the move. A common illustrative set enters on a close above the prior 20-bar high and exits on a close below the prior 10-bar low. The lookbacks are choices to test, not recommendations.

How does moving average trend following work?

Moving average trend following treats the trend as up while the close is above an N-bar moving average, or while a shorter average is above a longer one. The position is held in that direction and closed when the condition reverses. Averages lag price, so entries and exits come after turns, and ranges produce repeated reversals.

What is a Donchian trend following system?

A Donchian trend following system uses channels created by Richard Donchian: the highest high and lowest low of the last N bars. A long entry triggers on a close above the prior upper channel. Exits often use a shorter channel's low, so the stop rises as the trend continues. Results depend on market, lookbacks and costs.

Why does trend following lose on most trades?

Trend following often loses on most trades because each false start is cut at a small stop, while winners run until a trailing exit. Researchers describe the resulting returns as positively skewed. Few wins can cover many small losses only when the wins are large enough after costs, which a test on your own market must show.

Does automating trend following improve results?

Automating trend following executes the same entries and exits without skipping signals, including the many small losing trades the approach produces. Automation does not create an edge the rule lacks and does not remove slippage or gaps. Test the rule after costs, then verify on a demo account that each alert produces the intended broker order.

Reviewed 25 September 2026. Facts were checked against the linked sources on that date. Nothing in this article was tested on a trading account and no code was compiled.

Sources

  1. AQR – Time Series Momentum (Moskowitz, Ooi and Pedersen, Journal of Financial Economics, 2012), accessed 25 September 2026.
  2. TradingView Help Center – Donchian Channels (DC), accessed 25 September 2026.
  3. arXiv – Risk Premia: Asymmetric Tail Risks and Excess Returns (Lempérière, Deremble, Nguyen, Seager, Potters and Bouchaud), accessed 25 September 2026.
  4. arXiv – The Science and Practice of Trend-Following Systems (Sepp and Lucic, preprint, 2026), accessed 25 September 2026.
  5. TradingView – Pine Script User Manual: Strategies, accessed 25 September 2026.
  6. TradingView – Pine Script User Manual: Alerts, accessed 25 September 2026.
  7. TradingView – Pine Script User Manual: Repainting, accessed 25 September 2026.
  8. PineConnector – Syntax: message structure and PineConnector pip, accessed 25 September 2026.
  9. PineConnector – Syntax: modify open positions, accessed 25 September 2026.
  10. PineConnector – Syntax: pip trailing parameters, accessed 25 September 2026.
  11. PineConnector – Pine Script converter: supported behaviour, accessed 25 September 2026.
  12. PineConnector – Demo testing: test an active setup on a broker demo account, accessed 25 September 2026.
  13. MetaQuotes – MetaTrader 5 Help: orders, deals and positions, accessed 25 September 2026.
  14. PineConnector – Frequently asked questions: price differences, accessed 25 September 2026.
  15. PineConnector – Analytics: win rate, reward-to-risk and expectancy, accessed 25 September 2026.
  16. PineConnector – Keep strategies separate: closing with comments, accessed 25 September 2026.

PineConnector executes the instructions you send it. It does not select trades, manage money, or hold funds. Trading carries risk, and past performance of any strategy does not indicate future results.

Back to PiCo Blog

Run your strategies on our managed infrastructure

Bridge routes TradingView alerts to MetaTrader. Edge hosts and runs MT5 for you.

Core Trial

Then $59/month unless you cancel.

$7for 7 days

  • 1 account connection
  • 1 hosted MT5
  • Unlimited alerts, routed by Bridge
Try Core for $7

Trusted by 66,000+ traders in 156 countries and territories · <1s typical latency

Your Edge MT5 runs in our cloud · nothing to install · built on Microsoft Azure