Loading…

Autocorrelation Mode Switch System

Most single-rule systems assume the market is either trending or mean reverting for the whole time they are attached, when in reality that character changes. Lag-1 autocorrelation of bar-to-bar returns is a standard, genuinely computable statistic for which state the market is currently in: a positive reading means a bar's return tends to be followed by a same-signed return (momentum), a negative reading means it tends to be followed by an opposite-signed return (reversion). This EA recomputes that autocorrelation over a rolling InpAcfWindow-bar window on every closed bar - not once at startup - and trades whichever rule the current sign implies, provided |autocorrelation| clears InpMinAbsAcf. Below that threshold the reading is treated as noise and the EA stays flat rather than guessing. Because the regime can flip while a position is open, an open position is always closed the instant the active mode changes, before any new signal is considered. A momentum-mode position being managed by reversion-mode logic (or vice versa) would not make sense - the reason the trade was opened no longer holds once the underlying statistic flips sign. Both versions compute the autocorrelation the same way: a single bulk read of the last InpAcfWindow+3 closes, then one pass of mean/variance arithmetic over that array. Nothing in this indicator is computed per lag from a live indicator call, so there is no repeated handle lookup to slow it down on either platform. Notes and limitations - Autocorrelation is a statistical tendency measured over a finite window, not a guarantee about the next bar. A short window reacts fast but is noisier; a long window is smoother but slower to reflect a genuine regime change. - One position at a time, tracked by InpMagicNumber, and it is always flattened on a mode flip regardless of open profit or loss. - Evaluated once per closed bar, not on every tick. - No news, spread or session filter - add one if the raw signal trades through conditions you would rather avoid. - On MQL5 netting accounts, the EA has no guard against a foreign position already open on the same symbol; see the differences section above before running it alongside other EAs or manual trading on the same symbol.

Expert advisor · MT5 · v1.0 · Free

About Autocorrelation Mode Switch System

Autocorrelation Mode Switch System is an expert advisor (trading robot) for MetaTrader 5. It has 9 settings, such as Acf window, Min abs acf and Stop loss pips. MQL source code included.

Files in the download: AutocorrelationModeSwitch.ex5, AutocorrelationModeSwitch.mq5, AutocorrelationModeSwitch.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Acf window60Bars used to measure rolling lag-1 autocorrelation
Min abs acf0.10Minimum |autocorrelation| required to trade at all (else flat)
Stop loss pips40Stop loss distance, in pips (0 = none)
Take profit pips0Take profit distance, in pips (0 = none)
Fixed lots0.10Fixed lot size
Magic number20260360Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Momentum · Trend · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria