Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
The Mann Kendall Trend Confirmation strategy is a trend-following system for MetaTrader 5 that uses the Mann-Kendall test — a nonparametric, rank-based statistic borrowed from environmental science and hydrology — as its core trend filter. Instead of relying on a moving-average slope or an ordinary least-squares regression line, this approach asks a very specific statistical question: is the recent sequence of closing prices rising or falling more consistently than random chance would allow? Because the test looks only at the order of prices rather than their magnitude, a few outlier candles cannot manufacture a fake trend or mask a genuine one.
The strategy is designed for trending market conditions on liquid instruments such as major forex pairs or metals. It pairs the statistical trend filter with a classic pullback-and-reclaim entry pattern and an ATR-based risk framework, so it only looks for entries when a monotonic trend has been statistically confirmed and price offers a shallow retracement to enter on. This combination of a rigorous trend gate plus a defined entry trigger is intended to reduce the tendency to chase already-extended moves.
As a learning tool, this strategy is well suited to intermediate traders who want to understand how statistical significance testing can be applied to price data. You will learn how rank-based statistics differ from conventional indicators, how a z-score threshold controls signal selectivity, and how to combine a trend filter with volatility-adjusted stops. It is framed here as a study in strategy design and market analysis, not as a profit opportunity.
How It Works
The strategy processes only completed bars on a single timeframe (the chart's current period). On each new bar it recomputes the Mann-Kendall statistic and evaluates its entry and exit rules.
Building the trend signal:
- The strategy collects the last
MkPeriodcompleted closes, ordered oldest to newest. - It computes S, the sum over every pair of closes of the sign of (later close − earlier close). Each later close that is higher adds +1, each lower one subtracts 1.
- A strongly positive S means nearly every pair is increasing (a clean uptrend); a strongly negative S means a downtrend; a value near zero means no directional order (choppy, sideways price).
- S is standardized into a z-score using the null-hypothesis variance
Var(S) = n(n−1)(2n+5) / 18, with the standard ±1 continuity correction. The larger the absolute z-score, the more statistically significant the monotonic trend. - A z-score at or above
ZThresholdsignals a confirmed uptrend; at or below the negative threshold signals a confirmed downtrend.
Long entry — the strategy signals a buy when all of the following hold:
- The z-score is at or above
+ZThreshold(confirmed uptrend). - The prior completed bar was a red pullback bar (its close was below its open).
- The just-completed bar is a bullish reclaim (its close is above its open) and closes back above the pullback bar's high.
Short entry — the strategy signals a sell when the mirror conditions hold:
- The z-score is at or below
−ZThreshold(confirmed downtrend). - The prior completed bar was a green pullback bar (its close was above its open).
- The just-completed bar is a bearish break (its close is below its open) and closes below the pullback bar's low.
Stop-loss logic:
- On entry, the strategy measures the Average True Range (ATR) — a volatility gauge — over
AtrPeriodbars. - The stop distance is set to
AtrStopMult × ATR, placing the stop below entry for longs and above entry for shorts. Wider volatility produces a wider stop automatically.
Take-profit logic:
- The take-profit is placed at
RewardRiskRatio × stop distanceaway from entry, giving a fixed reward-to-risk ratio on every trade.
Early exit on trend reversal:
- If a position is open and the Mann-Kendall z-score flips and becomes significant in the opposite direction, the strategy closes the position early — treating a confirmed statistical reversal as a reason to step aside rather than wait for the stop.
- The strategy never stacks a new entry on top of a live position; it manages one position at a time per symbol.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| MkPeriod | 20 | 8 | 40 | Number of completed closes fed into the Mann-Kendall test. Larger values smooth the trend read and react more slowly; smaller values are more responsive but noisier. |
| ZThreshold | 1.64 | 0.80 | 3.00 | Significance threshold on the absolute z-score. Roughly 1.28 ≈ 90%, 1.64 ≈ 95%, 2.33 ≈ 99% one-sided confidence. Higher values demand stronger, rarer trends. |
| AtrPeriod | 14 | 5 | 30 | Number of bars used to calculate the ATR that sizes the stop-loss. |
| AtrStopMult | 1.5 | 0.5 | 4.0 | Stop distance as a multiple of ATR. Higher values give wider stops and more breathing room. |
| RewardRiskRatio | 1.8 | 1.0 | 4.0 | Take-profit distance as a multiple of the stop distance. A value of 1.8 targets 1.8 units of reward for every 1 unit of risk. |
| Lots | 0.10 | 0.01 | 1.0 | Fixed order volume in lots. Should be adjusted to your account size and risk tolerance. |

Recommended Chart Settings
The strategy was designed with trending forex pairs and metals in mind — for example EURUSD or XAUUSD (gold) — on intermediate timeframes such as M30 to H4. These timeframes tend to produce sustained directional moves that the Mann-Kendall test can identify while filtering out much of the intrabar noise found on very low timeframes.
Because the timeframe is never hardcoded, the EA runs on whatever period the chart is set to. That flexibility means you should test carefully: results will vary considerably across different symbols, timeframes, and market regimes. A setting that historically suited one instrument may behave very differently on another.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
What to Consider Before Using This EA
Strengths of this approach. The Mann-Kendall test is genuinely robust to outliers because it evaluates only the ordering of prices, not their size. A single spike candle — common around news events — cannot fabricate a trend signal the way it can distort a moving-average slope. The z-score threshold also gives you a clear, statistically meaningful dial for how selective you want to be. The pullback-and-reclaim entry adds structure, so the strategy waits for a retracement rather than buying at the top of an extended run, and the ATR-based stop adapts to changing volatility automatically.
Known limitations. Like all trend-following systems, this strategy is designed for trending conditions and may underperform in ranging or choppy markets, where the z-score rarely reaches significance or where confirmed trends reverse quickly. Because it acts only on completed bars and requires a specific two-bar pullback-reclaim pattern, valid trends may pass without ever producing a qualifying entry. The one-sided z-score reasoning assumes a reasonably continuous price series; unusual gaps, thin liquidity, or highly mean-reverting instruments can weaken the signal. Finally, a fixed reward-to-risk target means take-profits may be hit before a large trend fully matures, or missed entirely if price reverses before reaching the target.
Market conditions where it may struggle. Extended sideways consolidation, low-volatility regimes, and violently whipsawing markets are the classic weak spots for statistical trend filters. The early-exit-on-reversal rule helps limit exposure when a trend genuinely flips, but it can also close positions prematurely during a deep but temporary retracement.
Risk Management Tips
- Risk a small, fixed fraction per trade. A common educational guideline is to risk no more than 1–2% of account equity on any single position. Adjust the
Lotsparameter so the ATR-based stop distance corresponds to that fraction of your balance. - Test on a demo account first. Run the strategy on a demo or paper account across different market conditions before considering any live use, so you understand its behavior and drawdown profile.
- Understand drawdown. Every strategy experiences losing streaks. Study how many consecutive losses the system could produce and confirm you are comfortable with that worst case before committing capital.
- Size positions to survive, not to maximize. Larger lots amplify both gains and losses. Conservative sizing keeps you in the game long enough to evaluate a strategy fairly.
- Never trade money you cannot afford to lose, and treat automated systems as tools that still require ongoing monitoring, not set-and-forget solutions.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: MannKendallTrendConfirmation.ex5 (63 downloads)
- Source Code: MannKendallTrendConfirmation.mq5 (63 downloads)
- Documentation: MannKendallTrendConfirmation.pdf (59 downloads)