RA Mean Reversion Portfolio
RA Mean Reversion Portfolio is a multi-pair Expert Advisor for MetaTrader 5. It looks for
statistically stretched daily moves on two currency pairs and trades on the assumption that
such moves tend to return to the recent average. Both pairs are traded from one chart and
controlled as a single portfolio with one risk limit. Every trade is protected by a Stop Loss.
Strategy type: multi-currency portfolio mean reversion on D1 (counter-trend by design).
The Expert Advisor works on D1 bars only, keeps one position per symbol, and uses no grid,
averaging or martingale.
Advantages
- Simple, fully deterministic logic. The signal is a z-score of the daily close, so every
decision can be recalculated and checked by the user. There is no hidden adaptive component.
- One portfolio, one risk limit. Risk per trade is fixed, total portfolio risk is capped, and
the number of concurrent positions is limited.
- Correlation filter. A new trade in a pair that is highly correlated with an already open
position is taken at half risk, and two such correlated positions block further entries.
- Protective Stop Loss on every trade, calculated from the ATR at entry. It is never widened,
and there is no take profit that would interfere with the exit rules.
- Skip instead of over-risk. If the calculated volume is below the broker minimum, the trade
is not opened at all, so the risk per trade is never exceeded.
- Protection module. New entries are paused during a deep drawdown from the equity peak and
after a large loss during the current day.
- Anti-revenge pause. After a Stop Loss the Expert Advisor waits and requires the z-score to
return inside the entry threshold before it trades again.
- Broker friendly. Symbol names with prefixes or suffixes are found automatically, free margin
is checked before every order, and the program works on both netting and hedging accounts.
- CSV trade journal. Every closed trade is written to a file with direction, prices, z-scores,
result and exit reason for independent analysis.
- All input names and log messages are in English.
How it works
For every configured symbol the Expert Advisor calculates the z-score of the logarithm of the
daily close over a rolling window:
z = (logarithm of close - window average) / window standard deviation
The window is 45 daily bars by default and excludes the bar that produced the signal, so all
calculations are made on closed bars only and the signal does not repaint.
- If z is greater than +2.0, the pair is statistically stretched upwards, and the Expert
Advisor sells.
- If z is less than -2.0, the pair is statistically stretched downwards, and the Expert
Advisor buys.
- The position is closed when z returns to 0, when the maximum holding time of 25 daily bars
is reached, or by the Stop Loss.
The Stop Loss distance is the ATR(14) multiplied by 1.5 at the moment of entry. The position
size is calculated from this distance and the configured risk percentage, using the tick value
and tick size of the symbol.
Risk management
- Risk per trade: 0.3% of the account balance by default.
- Total risk of all open positions: 1.5% of the balance by default.
- Maximum number of concurrent positions: 3 by default.
- Emergency protection: no new entries while the drawdown from the equity peak exceeds 15% or
after a 3% loss during the current day.
- Open positions are always managed by their own rules; the protection module only stops new
entries.
Supported symbols and accounts
- Default symbols: EURGBP and AUDUSD on the D1 timeframe, the two pairs the parameters were
fitted and tested on.
- Other currency pairs can be listed in the input parameters and will be traded, but the model
was not optimized for them.
- Symbol names are matched by letters and digits only, so EURGBP, EURGBP.a or EURGBPm are
found automatically. If none of the listed symbols exists on the account, the Expert Advisor
trades the chart symbol instead of refusing to start.
- Accounts: netting and hedging are both supported. Positions are opened one per symbol, closed
by their own ticket and filtered by the magic number, so manual trades and trades of other
Expert Advisors are not affected.
- Timeframe: attach the Expert Advisor to any D1 chart. The traded pairs come from the inputs.
What this Expert Advisor does not do
- No grid, no averaging, no martingale, no lot increase after a loss.
- No trailing stop and no break-even move: the Stop Loss is set at entry and stays there.
- No take profit: exits are the z-score return, the maximum holding time or the Stop Loss.
- No news or economic calendar filter.
- No multi-timeframe logic: the model works on D1 bars only.
- It never opens a position against an existing position of the same symbol.
Requirements
- MetaTrader 5 with automated trading enabled in the terminal and allowed for the Expert
Advisor.
- Recommended deposit: 5000 USD/EUR or more; the test below was made with 10000 EUR. The Expert
Advisor skips a trade when 0.3% of the balance cannot cover the minimum lot of 0.01. With
typical daily ATR stops on these pairs that threshold is about 2900 EUR for EURGBP and about
4400 USD for AUDUSD.
- Leverage: 1:30 or higher is sufficient, because only a small part of the available margin is
used.
- Daily history of at least 47 bars per symbol; the correlation filter uses 90 bars.
Test results
The figures below were obtained in the MetaTrader 5 Strategy Tester (build 6241) with the
default settings. They are the result of a historical simulation and are not real trading
results.
- Period: 2020.01.01 - 2026.10.09, about 6.75 years
- Symbols: EURGBP D1 and AUDUSD D1, traded from one EURGBP D1 chart
- Model: every tick; deposit 10000 EUR; leverage 1:100
- Net result: +887.09 EUR, final balance 10887.09 EUR
- Trades: 124; profit factor 1.59; winning trades about 57%
- Maximum balance drawdown: 1.58% (174 EUR); maximum equity drawdown: 1.78% (197 EUR)
- Sharpe ratio per trade: 1.13
- AUDUSD: 65 trades, +272 EUR, profit factor 1.30
- EURGBP: 58 trades, +610 EUR, profit factor 2.06
- By year: 2020 +98.66 EUR (17 trades), 2021 +219.40 (18), 2022 +147.65 (18),
2023 +329.10 (20), 2024 +41.47 (20), 2025 +130.26 (19), 2026 until 09.10 -85.25 (11)
How to read these numbers
- The result is not evenly distributed in time. The strongest year (2023) gives about a third
of the total, 2024 was close to flat, and the partial year 2026 is negative. A mean-reversion
model works best in ranging markets and is expected to perform worse in strong trends.
- The test uses the spread history, swaps and commission settings of the testing account. At
another broker the result will differ.
- Backtest results and past performance do not guarantee future results.
Input parameters
Portfolio:
- InpPairs = EURGBP,AUDUSD - traded symbols separated by commas
- InpMaxPositions = 3 - maximum number of concurrent positions
- InpRiskPct = 0.3 - risk per trade as a percentage of the account balance
- InpMaxPortfolioRiskPct = 1.5 - maximum total risk of all open positions as a percentage of
the balance
Correlation module:
- InpUseCorr = true - enable the correlation filter
- InpCorrWindow = 90 - correlation window in daily bars
- InpCorrMax = 0.7 - correlation threshold that halves the risk of a new entry
Core (z-score on D1):
- InpZWin = 45 - z-score window in daily bars
- InpEntry = 2.0 - entry threshold for the absolute value of z
- InpExitZ = 0.0 - z-score level at which a position is closed
- InpMaxHold = 25 - maximum holding time in daily bars
- InpATRPeriod = 14 - ATR period used for the Stop Loss
- InpATRMult = 1.5 - ATR multiplier used for the Stop Loss
Protection:
- InpMaxDDStopPct = 15.0 - block new entries above this drawdown from the equity peak, in
percent
- InpDailyLossStopPct = 3.0 - block new entries above this loss during the current day, in
percent
- InpSLCooldownBars = 5 - pause after a Stop Loss in daily bars (0 = off)
Service:
- InpRequireNeutralReset = true - after a Stop Loss wait until the absolute value of z is back
inside the entry threshold
- InpMagic = 1544010 - magic number, must be unique per chart
- InpSlippage = 30 - allowed slippage in points
- InpJournal = true - write a CSV trade journal
- InpJournalFile = AI_Portfolio_trades.csv - journal file name
- InpJournalCommon = false - write the journal to the common folder instead of the terminal
data folder
Installation
1. Install the Expert Advisor from the Market, or copy the file to the Experts folder of the
terminal.
2. Attach it to any D1 chart and allow automated trading for the Expert Advisor.
3. Make sure automated trading is enabled in the terminal.
4. Check the Experts log: the Expert Advisor prints the resolved symbols, the account margin
mode and the active settings at startup.
Disclaimer
Trading in financial markets involves risk of loss.
This Expert Advisor implements a defined trading logic. It does not predict the market and does
not promise any profit.
Results obtained in the MetaTrader 5 Strategy Tester are the results of a historical simulation
and are not real trading results.
Past performance does not guarantee future results.
Test the product on a demo account before using it on a live account, and never risk money you
cannot afford to lose.