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 Sequence Complexity Trend Shift strategy is a regime-transition trend system built on Lempel-Ziv complexity — an information-theory statistic that measures how compressible, and therefore how predictable, a sequence of symbols is. Instead of reading price levels or volatility directly, this strategy translates the recent market into a string of up/down bits and asks a single question: how much genuine structure is hidden in that pattern? When the answer shifts from "random noise" to "organized structure," the strategy interprets that moment as the possible birth of a directional leg and looks to trade in the direction the sequence is leaning.
At its core, the strategy maps each close-to-close change over a rolling window into a binary digit — 1 for an up bar, 0 for a down bar — and parses the resulting string with the classic LZ76 dictionary algorithm. The phrase count is normalized toward the value you would expect from a pure coin-flip series. A reading near 1.0 means the up/down pattern is essentially incompressible: a directionless chop where every bar is a fresh guess. A markedly lower reading means the pattern has become repetitive and compressible, which historically coincides with a persistent, same-signed run of closes — the signature of a forming trend.
This makes the strategy a useful learning tool for traders who want to understand regime detection and information-theoretic filters rather than conventional moving-average crossovers. It is designed for markets that alternate between choppy, sideways phases and cleaner trending legs, and it is best suited to students of algorithmic trading who are curious about how statistical structure — rather than price alone — can be used to time entries. It is an analytical framework for study, not a shortcut to returns.
How It Works
The strategy evaluates one completed bar at a time on the chart's primary timeframe. It combines three independent filters — a complexity read, a net directional bias, and an EMA price gate — before it acts.
- Building the sequence: Over the last
Windowbars, each close-to-close change becomes a bit (1 up, 0 down). This binary string is parsed with the Lempel-Ziv algorithm to produce a normalized complexity value,LZnorm. - Reading structure: A high
LZnorm(near 1.0) signals incompressible, coin-flip chop. A lowLZnormsignals a compressible, structured sequence — the strategy's definition of an emerging trend. - The net sign bias: Because a strict alternating pattern (0101…) is also compressible but not directional, the strategy pairs complexity with a net sign bias — up-bars minus down-bars over the window. Only a compressed sequence that also leans decisively one way is treated as a genuine trend.
- The transition trigger: The edge is captured on the collapse. The strategy signals only on the bar where
LZnormfirst drops from at or above theMaxComplexitythreshold down through it. That fresh collapse marks the moment order crystallizes out of noise. - Long entry: The strategy signals a long when the complexity has just collapsed below the threshold, the net bias is positive beyond
MinBias, and the close is above the EMA. - Short entry: The strategy signals a short when the complexity has just collapsed below the threshold, the net bias is negative beyond
MinBias, and the close is below the EMA. - Stop-loss logic: On entry, a stop is placed at
AtrStopMultmultiples of the current ATR away from the fill price — below price for longs, above for shorts — so risk scales with prevailing volatility. - Take-profit logic: A target is placed at
AtrTargetMultmultiples of ATR in the trade's favor, giving a volatility-adjusted reward-to-risk ratio. - Early regime-failure exit: Beyond the fixed stop and target, the strategy closes the position early if
LZnormclimbs back aboveMaxComplexity × ExitCplxMult. This may indicate the structured sequence has dissolved back into an unpredictable coin-flip — a sign the directional leg is over. - Position discipline: Only one position per magic number is held at a time; the strategy never stacks entries.

Strategy Parameters
| Parameter | Default | Min | Max | Description | ||
|---|---|---|---|---|---|---|
| Window | 40 | 20 | 90 | Rolling window, in bars, that the return-sign sequence and complexity are built on. | ||
| MaxComplexity | 0.85 | 0.55 | 1.10 | Normalized LZ threshold; below it the sequence is judged "structured." | ||
| MinBias | 0.10 | 0.00 | 0.40 | Minimum net sign bias ( | up − down | / N) required to call a direction. |
| EmaPeriod | 50 | 10 | 100 | EMA length used as the price-direction confirmation gate. | ||
| ExitCplxMult | 1.05 | 1.00 | 1.50 | Early-exit level; close when LZnorm climbs back above MaxComplexity × this. | ||
| AtrPeriod | 14 | 7 | 40 | Averaging period for the ATR used in stops and targets. | ||
| AtrStopMult | 2.0 | 1.0 | 5.0 | ATR multiple that sets the stop-loss distance. | ||
| AtrTargetMult | 3.0 | 1.0 | 8.0 | ATR multiple that sets the take-profit distance. | ||
| Lots | 0.10 | 0.01 | 1.0 | Fixed order volume in lots. |

Recommended Chart Settings
The strategy is timeframe-agnostic by design: every bar reference uses the chart's primary timeframe, so nothing is hardcoded and the logic adapts to whatever period you attach it to. As a starting point for study, mid-range timeframes such as the H1 or H4 on liquid major forex pairs (for example EUR/USD or GBP/USD) tend to give the rolling window enough clean bars to form a meaningful sign sequence without excessive noise.
Because the complexity read depends on the character of each market's up/down rhythm, results will vary considerably across different symbols, sessions, and volatility regimes. Treat the defaults as a neutral baseline and always validate any timeframe or symbol choice on your own historical 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
The appeal of a Lempel-Ziv approach is that it is scale-independent: it reads only the pattern of up and down closes, so it is not distorted by price magnitude or by a single volatile spike the way many indicators are. Pairing the complexity collapse with a net sign bias and an EMA gate is a sensible triple-confirmation design — it filters out the alternating-chop patterns that complexity alone would misread, and it demands price agree before committing. The ATR-based stops and targets also let the strategy's risk scale sensibly with current conditions.
That said, this is not a universal edge. Complexity statistics are inherently noisy on short windows, and the "collapse" trigger can fire on brief structured pockets that fail to develop into real trends — producing whipsaw entries in genuinely rangebound markets. The threshold and bias parameters interact in ways that are sensitive to the symbol and timeframe, so a setting that historically looked reasonable on one market may behave very differently on another. Like all trend-transition systems, it may underperform during choppy, mean-reverting conditions where clean directional legs simply do not form, and it can be late to established trends because it waits for a fresh collapse rather than an ongoing move. Finally, the fixed lot sizing does not adapt to account equity, so position risk should be reviewed manually.
Approach this EA as a framework to study how information theory can be applied to market structure — not as a finished, plug-and-play system. Understanding why each filter exists will serve you far better than running the defaults blindly.
Risk Management Tips
Sound risk management matters more than any single entry signal. Consider the following general principles as you study this strategy:
- Position sizing: Size each trade so that a full stop-loss hit costs only a small, predefined fraction of your account. A common educational guideline is to risk no more than 1–2% of account equity per trade.
- Use a demo account first: Test the strategy on a demo or simulation environment until you understand its behavior across different market conditions before considering any live capital.
- Understand drawdown: Every strategy experiences losing streaks. Review the maximum historical drawdown and ask whether you could tolerate it emotionally and financially.
- Respect the stops: The ATR-based stop-loss exists to cap risk on each trade. Avoid the temptation to widen or remove it after a losing sequence.
- Diversify and avoid over-leverage: Concentrating risk in one symbol or using excessive leverage can amplify losses quickly. Keep leverage conservative while you learn.
- Keep a trading journal: Recording why each signal fired and how it resolved will teach you far more about the strategy than raw performance figures alone.
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: SequenceComplexityTrendShift.ex5 (12 downloads)
- Source Code: SequenceComplexityTrendShift.mq5 (16 downloads)
- Documentation: SequenceComplexityTrendShift.pdf (21 downloads)