Blog / Strategy
Strategy

Sequence Complexity Trend Shift

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.

Lempel-Ziv complexity MT5 EA
Illustrative example of the strategy’s entry and exit logic — not real trading results.

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.
Lempel-Ziv complexity MT5 EA — MQL5 source code

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

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:

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

← Back to Blog