Dynamic averaging
This EA implements a dynamic averaging strategy that opens positions when price deviates significantly from a calculated average, aiming to profit from price reversion to the mean. It dynamically adjusts the averaging period and thresholds based on market volatility conditions. The system manages multiple orders with incremental lot sizing as price moves further from the average.
Open the interactive view (equity curve, symbol switch)Key facts
Backtest results (H1, about 1 year)
| Symbol | P&L | Annual | Max DD | Trades | Win rate | Sharpe | Recovery | Losing streak | Per trade | Status |
|---|---|---|---|---|---|---|---|---|---|---|
| EURUSD | -1.73% | -1.50% | 4.50% | 108 | 47.70% | -0.39 | -0.38 | 8 | −$1.29 | Reliable |
| GBPUSD | +6.18% | +5.35% | 3.15% | 110 | 54.50% | 1.20 | 1.96 | 7 | +$5.62 | Reliable |
| USDJPY | +1.00% | +0.87% | 4.67% | 110 | 49.10% | 0.23 | 0.21 | 7 | +$0.91 | Reliable |
| XAUUSD | -53.83% | -47.20% | 76.76% | 109 | 46.30% | 0.09 | -0.70 | 9 | −$47.55 | Reliable |
Profitable on 2 of 4 markets with reliable results.
Converted from MQL5 to Python and run with the same rules for every EA. Positions use MT5 lot sizes (100,000 units per FX lot, 100 oz per gold lot) with 1:100 leverage, one order at a time, and a stop-out below 10% of the starting balance. Sharpe is computed from the equity curve. Results marked as unreliable are shown for completeness only.
Against the other Mean Reversion EAs with a reliable result on the same market: EURUSD: better than 57% of 30 · GBPUSD: better than 91% of 32 · USDJPY: better than 50% of 32 · XAUUSD: better than 26% of 31
Month by month
| Market | Months with a gain | Best month | Worst month |
|---|---|---|---|
| EURUSD | 31% | +3.35% 2026-04 | -1.57% 2026-10 |
| GBPUSD | 77% | +3.11% 2026-04 | -2.21% 2026-01 |
| USDJPY | 38% | +2.99% 2026-04 | -1.91% 2026-03 |
| XAUUSD | 38% | +71.39% 2026-04 | -49.17% 2026-08 |
From the backtest equity curve, sampled about every two days; only reliable results.
Blow-up risk: No blow-up pattern found
None of the usual blow-up patterns were found in the code, and the account was not stopped out in our backtests. That is not a guarantee: any EA can lose money.
High: stopped out in our backtest, or martingale/grid sizing without a stop loss. Elevated: martingale or grid sizing with a stop loss, or several positions at once without a stop loss. What the label means and what we found →
Strategy analysis
The strategy concept is based on dynamic mean reversion, assuming that when price deviates significantly from a moving average, the market is overextended and price will revert to the mean. Entry conditions trigger when price deviates beyond a set threshold percentage from the dynamically calculated average, with an initial position opened on the first deviation and additional positions added as deviation increases. Exit conditions close all positions when price returns near the average or reaches a take-profit target. Position sizing uses incremental lot increases, where each additional order scales up by a configured multiplier, similar to averaging down cost basis. Money management calculates initial lot size based on account balance and risk parameters, but incremental position additions can lead to excessive total exposure. The strategy lacks a hard stop-loss, creating risk of sustained position accumulation leading to significant drawdowns.
Strengths
- Dynamically adjusting the averaging period adapts to different market volatility regimes, offering more flexibility than fixed-period moving averages
- Mean reversion strategy performs well in ranging markets with clear and understandable logic
- Incremental position sizing accelerates breakeven and profit when price reverts
- Maximum order count limit provides some control over total risk exposure
- Magic number for order management prevents conflicts with other EAs
Weaknesses
- Lack of hard stop-loss means sustained position accumulation in trending markets can lead to catastrophic losses
- Incremental lot sizingessentially approaches martingale behavior, requiring exponentially growing capital
- Spread and slippage costs are not factored in, which can erode profits on short-term reversion trades
- Mean reversion performs poorly in strong trending markets without a trend filter mechanism
- Dynamic averaging parameter optimization risks overfitting to historical data
Possible improvements
- Add a hard stop-loss mechanism, either as a maximum acceptable loss percentage or fixed pip stop, to prevent unlimited position accumulation in one-directional markets
- Implement a trend filter (such as ADX or higher-timeframe moving average direction) to prohibit counter-trend averaging in strong trending conditions
Risk assessment
Overall risk: High risk
- Incremental position sizing without hard stop-loss can lead to account blow-up in extreme trending markets
- Maximum order limit of 5 still permits 5x incremental positions, potentially exceeding account capacity
- Lack of new bar check may cause multiple entries within the same candle
Evaluation scores
Parameters
| Parameter | Default | Description |
|---|---|---|
AveragingPeriod | 20 | Dynamic moving average calculation period |
DeviationThreshold | 0.5 | Opening deviation threshold percentage |
LotSize | 0.01 | Initial opening lot size |
LotMultiplier | 1.5 | position additionlot size multiplier |
MaxOrders | 5 | Maximum position additions |
TakeProfitPips | 50 | Take profit in points |
MagicNumber | 12345 | Unique order identifier number |
Similar Mean Reversion EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.