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 Permutation Entropy Regime Trend strategy is a trend-following pullback system that uses permutation entropy — a complexity statistic from information theory — as a filter to decide whether a market is genuinely trending or simply drifting as random noise. Permutation entropy (also called the Bandt-Pompe statistic, after the researchers who introduced it in 2002) measures how ordered or disordered a sequence of prices is, based purely on the rank-order shape of consecutive closes rather than their magnitudes. The strategy pairs this regime filter with a classic, low-risk entry: a with-trend reclaim of an exponential moving average (EMA) baseline.
The core idea is simple to state but statistically motivated. Take the last handful of closing prices and look only at their up/down ordinal pattern — for a triplet of prices there are exactly 3! = 6 possible shapes (rising, falling, peak, valley, and so on). Slide a window across the recent bars, count how often each of the six patterns appears, and compute the Shannon entropy of those frequencies, normalized to a value between 0 and 1. A reading near 1.0 means all patterns are roughly equally likely, which is the fingerprint of a random, choppy path. A lower reading means a few patterns dominate, which historically corresponds to a more ordered, trending path. Because the measure is rank-based, it is invariant to scale and to any monotonic transform, so a single threshold behaves consistently across FX majors, gold, indices, and crypto.
This strategy is best suited as a learning tool for traders who want to understand regime filtering — the practice of only taking a signal when the underlying market state supports it. It is not a shortcut and it is not a guarantee of anything. Instead, it is a clear, self-contained example of how a non-price statistic can be used to refuse trades that a naive pullback system would otherwise take. It was designed with M15–H1 majors and XAUUSD in mind, but the timeframe is never hardcoded — it uses whatever chart it is attached to.
How It Works
The strategy evaluates its logic only on closed bars, so its signals do not repaint. The currently-forming bar is used solely to detect when a new bar has opened. On each new bar, the system recomputes the normalized permutation entropy (PE) of the recent close path and then checks its entry, exit, and management rules.
Regime filter (the gate):
- The strategy computes PE over the last
PeWindowclosed bars using embedding dimension 3. - It only considers new trades when PE is below
PeThreshold— that is, when the path is statistically ordered rather than random. - If PE is at or above the threshold, no new trade is taken. This is the feature that makes the approach distinctive: it declines the same pullback when the recent path is indistinguishable from a random walk.
Long entry — the strategy signals a buy when all of the following hold:
- PE is below
PeThreshold(ordered regime confirmed). - The EMA baseline is rising (
emaNowgreater thanemaPrev), indicating an up-trend. - The prior close had dipped to or below the baseline (a pullback occurred).
- The latest close has reclaimed back above the current baseline (the pullback is resolving upward).
Short entry — the strategy signals a sell when the mirror conditions hold:
- PE is below
PeThreshold(ordered regime confirmed). - The EMA baseline is falling, indicating a down-trend.
- The prior close had popped to or above the baseline (a bounce occurred).
- The latest close has lost the baseline back to the downside.
Cooldown:
- After any entry, the strategy waits
CooldownBarsbars before it will consider another. This reduces churn on borderline reclaims that flicker around the baseline.
Exit and risk management:
- Every trade is opened with an ATR-based stop-loss and take-profit. The Average True Range (ATR) measures recent volatility; the stop is placed
SlAtrMult× ATR away from entry and the targetTpAtrMult× ATR away. Because the distances scale with volatility, the trade adapts to quiet and busy conditions alike. - In addition to the fixed stop and target, there is a regime-invalidation exit. If, while a trade is open, permutation entropy climbs back above
PeThreshold + ExitPeBuffer, the "ordered" thesis that justified the trade is considered gone, and the position is closed. This is a distinctive touch — the same statistic that opens trades can also close them. - The strategy holds only one position at a time per symbol; the ATR stop and target manage the trade once the regime remains valid.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| PeWindow | 40 | 20 | 120 | Number of closed bars the permutation entropy is measured over. Larger windows smooth the regime read but respond more slowly. |
| PeThreshold | 0.90 | 0.70 | 0.98 | Ordered-regime ceiling. New trades are only taken when normalized PE is below this value. Lower is stricter (fewer, more-ordered signals). |
| ExitPeBuffer | 0.04 | 0.00 | 0.15 | Extra entropy above the threshold that forces an open trade to close. Larger values make the regime-exit less trigger-happy. |
| EmaPeriod | 30 | 10 | 120 | Period of the EMA baseline that the pullback reclaim is measured against. |
| AtrPeriod | 14 | 7 | 30 | Lookback for the ATR used to size the stop-loss and take-profit. |
| SlAtrMult | 1.8 | 0.8 | 4.0 | Stop-loss distance as a multiple of ATR. |
| TpAtrMult | 3.0 | 1.0 | 6.0 | Take-profit distance as a multiple of ATR. |
| CooldownBars | 2 | 0 | 20 | Bars to wait between entries to avoid churn on borderline reclaims. |
| Lots | 0.10 | 0.01 | 2.0 | Fixed trade volume in lots. |

Recommended Chart Settings
This strategy was designed with M15 to H1 timeframes in mind, on liquid instruments such as EUR/USD, GBP/USD, USD/JPY, and XAUUSD (gold). Because permutation entropy is scale-invariant, the same PeThreshold is intended to be meaningful across these different instruments and across quiet versus volatile regimes — but that does not mean every instrument or timeframe will behave the same way. Trending, liquid markets on intraday timeframes give the entropy gate the cleanest signal to work with; very low-volatility or heavily ranging conditions naturally produce fewer qualifying setups. As with any strategy, results will vary across different market conditions, brokers, and spreads, so always evaluate it on your own data before drawing conclusions.
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 the approach. The permutation entropy gate is a genuinely different way to define "trend" — it reads the geometry of the recent path rather than the size of the moves, so it is robust to scale, outliers, and monotonic transforms. That makes a single threshold behave consistently across instruments, which is unusual for a filter. The pullback-reclaim entry it gates is a well-understood, low-risk pattern, and the regime-invalidation exit gives the system a principled reason to leave a trade early when its core assumption breaks.
Known limitations. Permutation entropy with embedding dimension 3 has only six possible patterns, so it is a coarse view of order — it can misclassify short bursts of structure inside otherwise noisy data, and vice versa. The strategy is by design a filter, so in genuinely choppy markets it may sit out for long stretches and produce very few trades. When it does trade, it inherits the usual weaknesses of moving-average pullback systems: whipsaws around the baseline during transitions, and false reclaims when a trend is actually rolling over. It also trades one position at a time, so it will not scale into a move. Slippage, spread, and swap costs — none of which appear in idealized logic — can meaningfully affect real outcomes, especially on lower timeframes.
Where it may underperform. Expect fewer and lower-quality signals during quiet, mean-reverting ranges (where entropy stays high) and during sharp news-driven spikes (where the ordinal structure changes faster than the window can track). Treat the defaults as a starting point for study, not a finished configuration.
Risk Management Tips
Sound risk management matters far more than any single entry rule. Consider the following general principles as part of your education:
- Risk a small, fixed fraction per trade. Many educational sources suggest risking no more than 1–2% of account equity on any single position. Size your
Lotsso that the ATR-based stop distance corresponds to that fraction, rather than using a fixed lot size blindly. - Understand drawdown. Even a strategy with a sound edge experiences losing streaks. Know the maximum consecutive losses you can tolerate emotionally and financially before you commit capital.
- Test on a demo account first. Run the EA on a demo or simulated account across a variety of market conditions to understand how often it trades and how it behaves during ranges, trends, and volatility spikes.
- Backtest and forward-test. Historical behavior is only a hypothesis. Validate parameters on out-of-sample data and, where possible, forward-test in real time before trusting any configuration.
- Account for costs. Include realistic spread, commission, and swap in any evaluation; these can turn a marginal edge into a losing one.
- Never over-leverage. Leverage amplifies losses as readily as gains. Keep position sizes conservative relative to your account.
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: PermutationEntropyRegimeTrend.ex5 (8 downloads)
- Source Code: PermutationEntropyRegimeTrend.mq5 (9 downloads)
- Documentation: PermutationEntropyRegimeTrend.pdf (14 downloads)