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 Sequential Record Imbalance strategy is a single-timeframe, trend-following expert advisor (EA) for MetaTrader 5 that measures market drift using record statistics — the mathematical theory of running maxima and minima — rather than a conventional indicator, chart pattern, or support/resistance level. Its only supporting indicator is the Average True Range (ATR), a volatility gauge used purely to size stops and targets. The core signal comes from counting how often price sets new highs versus new lows inside a rolling window of bars.
The idea rests on two classical results from probability theory. First, within any sequence, a bar is an upper record when its high exceeds every earlier high in the window, and a lower record when its low undercuts every earlier low. For a market with no directional bias (a "driftless" random walk), upper and lower records occur symmetrically, so their difference averages to zero. Genuine directional drift — a persistent tendency for price to move one way — is what breaks that symmetry: an uptrend renews highs far more often than lows, and a downtrend does the reverse. The strategy turns this imbalance into a normalized drift score and then measures how unusual that score is compared with the instrument's own recent behaviour.
This EA is best understood as a learning tool for traders who want to study trend-detection from a statistics-first angle. It suits those curious about distribution-free, self-calibrating signals and who already understand basic MT5 order handling. It is designed for trending market conditions and, like all trend-following systems, is expected to struggle in choppy, range-bound phases. Treat it as a framework for analysis and experimentation, not as a shortcut to results.
How It Works
The strategy evaluates signals only when a new bar has fully closed, which avoids "repainting" (signals that change as the current candle forms). Each completed bar is added to rolling arrays of highs, lows, and closes, and the logic then proceeds as follows.
- Record counting: Over the last
Windowcompleted bars, the strategy scans oldest to newest and counts upper records (new window highs) and lower records (new window lows). The first bar counts as both, and because that cancels out in the difference, the starting point does not bias the result. - Drift score: It computes a normalized score
s = (U − L) / √Window, whereUis the upper-record count andLthe lower-record count. A positivesindicates upward drift; a negativesindicates downward drift. Dividing by the square root of the window keeps the score on a consistent scale. - Self-adapting z-score: Rather than compare
sto a fixed threshold, the strategy standardizes it against its own recent history. It calculates a z-score — how many standard deviations the current score sits from the mean of the lastScoreLookbackscores. This is the adaptive component: it auto-calibrates per instrument and regime with no manual per-symbol tuning. If recent history is perfectly flat (no spread), no signal is produced. - Long entry: The strategy signals a long when the z-score is at or above
EntryZ, the raw scoresis positive, and the just-closed bar closed higher than it opened. All three must agree. - Short entry: The strategy signals a short when the z-score is at or below
−EntryZ,sis negative, and the just-closed bar closed lower than it opened. - Renewal-stall exit: An open long is closed once the z-score falls back to
ExitZor below — a sign the upward record renewal has stalled and drift is fading. An open short is closed once the z-score rises to−ExitZor above. - Stop-loss and take-profit: On entry, the stop-loss is placed
SlAtrMult × ATRaway from the fill price, and the take-profitTpAtrMult × ATRaway. Because both scale with ATR, risk distances adapt automatically to current volatility. - Breakeven protection: Once price has travelled
BreakevenAtr × ATRin the trade's favour, the stop is pulled up (or down, for shorts) to the entry price, aiming to reduce the risk of a winning trade turning into a loss. - One position at a time: The EA holds at most one position per magic number, keeping the drift bet clean and the risk bounded.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| Window | 40 | 15 | 120 | Number of completed bars in the rolling record window used to count upper and lower records. |
| ScoreLookback | 60 | 20 | 200 | How many past drift scores are used to standardize the current score into a z-score. |
| EntryZ | 1.20 | 0.50 | 3.00 | Z-score threshold required to trigger an entry; higher values demand more statistically extreme drift. |
| ExitZ | 0.30 | 0.00 | 1.50 | Z-score level at which an open position is closed because record renewal has stalled. |
| AtrPeriod | 14 | 7 | 28 | Number of bars used to calculate the ATR that sizes stops and targets. |
| SlAtrMult | 1.80 | 0.50 | 4.00 | Stop-loss distance expressed as a multiple of ATR. |
| TpAtrMult | 2.80 | 0.50 | 6.00 | Take-profit distance expressed as a multiple of ATR. |
| BreakevenAtr | 1.00 | 0.00 | 3.00 | Profit distance (in ATR multiples) at which the stop is moved to breakeven; 0 disables it. |
| Lots | 0.10 | 0.01 | 1.00 | Fixed trade volume in lots. |

Recommended Chart Settings
Because the record-imbalance method is designed to be distribution-free and self-calibrating, it is not locked to a single symbol. That said, trend-following logic generally behaves best on liquid instruments with sustained directional moves. A sensible starting point for study is a major forex pair such as EUR/USD on an intraday-to-swing timeframe like H1 or H4, where individual bars carry meaningful record information and noise is lower than on very short timeframes.
Keep in mind that results will vary considerably across different symbols, timeframes, and market conditions. Always test any configuration on historical data and a demo account before drawing conclusions, and re-check the Window and ScoreLookback values whenever you change timeframe, since they define the memory of the system in bars.
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 main strength of this approach is its theoretical independence from any single indicator. Record statistics are distribution-free, meaning the record-counting logic does not assume prices follow a particular statistical shape. The z-score standardization adds a genuinely adaptive layer, so the same settings can respond to very different instruments without manual retuning. Pairing entries with ATR-based stops and a breakeven mechanism also gives the system a disciplined, volatility-aware risk framework.
There are important limitations to weigh honestly. Like every trend-following method, Sequential Record Imbalance is built to profit from persistence, so it may underperform in ranging or mean-reverting markets, where drift is weak and records flip back and forth, producing whipsaw entries and repeated small losses. The z-score also needs a warm-up period before it can fire, so it does nothing until enough scores accumulate. During abrupt regime changes — for example, a sharp reversal after a long trend — the exit logic may lag, since it waits for record renewal to stall rather than reacting instantly to price. Finally, the fixed Lots sizing does not scale to account equity, and default thresholds are starting points, not optimized values.
Approach this EA as a study of how drift can be detected statistically, and validate every assumption yourself before relying on it.
Risk Management Tips
Sound risk management matters far more than any single entry rule. Consider these general principles as you study this EA:
- Position sizing: Size trades so that a losing trade 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 thoroughly in a risk-free demo environment until you understand its behaviour across trending and ranging conditions.
- Understand drawdown: Every strategy experiences losing streaks. Know the maximum peak-to-trough decline you are willing to tolerate, and stop to reassess if it is exceeded.
- Respect leverage: Leverage magnifies both gains and losses. Lower leverage gives you more room to survive adverse moves.
- Keep records: Log your settings, results, and observations so you can learn systematically rather than reacting emotionally.
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: SequentialRecordImbalance.ex5 (0 downloads)
- Source Code: SequentialRecordImbalance.mq5 (0 downloads)
- Documentation: SequentialRecordImbalance.pdf (0 downloads)