Futures Portfolio Control Expiration
This EA manages a portfolio of up to 3 futures contracts by automatically rolling positions to the next expiration month when the current contract nears expiration. It continuously monitors SYMBOL_EXPIRATION_TIME and closes/rolls positions before the cutoff. The user pre-configures symbols and lot sizes (positive for long, negative for short) to maintain a hedged portfolio.
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 | -3.24% | -2.82% | 8.82% | 1 | 0.00% | — | — | — | — | Same as other EAs |
| GBPUSD | +2.78% | +2.41% | 6.56% | 1 | 0.00% | — | — | — | — | Same as other EAs |
| USDJPY | +2.41% | +2.09% | 6.62% | 1 | 0.00% | — | — | — | — | Same as other EAs |
| XAUUSD | -7.56% | -6.29% | 65.89% | 1 | 0.00% | — | — | — | — | Same as other EAs |
On every market this backtest is identical to EA-16786. The automatic conversion almost certainly lost what makes this EA different (a custom indicator, a filter or the money management), so these results are not ranked or counted.
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.
Blow-up risk: Elevated
- Has no stop loss or trailing stop
- Can hold up to 3 positions at once
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 core concept of this EA is futures portfolio expiration roll management rather than a traditional directional trading strategy. Entry conditions are simple: when no position exists on a selected futures contract, it automatically opens one based on the pre-configured lot size — positive lots for long positions, negative lots for short positions. The sole exit condition is when the contract's expiration time is within hours_before_expiration hours from the current time, at which point it closes the position and rolls to the next month's contract. Position sizing is entirely user-configured with no dynamic adjustment or money management logic. The EA uses Sleep(3000) for delay operations, which is not best practice in MQL5 as it blocks the entire EA thread. The NextFutures function logic is somewhat complex, iterating through the next 12 months to find the next unexpired contract, but it has a potential flaw — when currtime!=0, it stops as soon as it finds a contract with expiration beyond currtime, which may not always select the correct next contract in all scenarios.
Strengths
- Automatic roll-over functionality avoids the risk of futures contract expiration/delivery, which is very practical for traders holding long-term portfolio positions
- Supports multi-symbol portfolio management (up to 3 contracts) with mixed long/short configuration, suitable for hedging strategies
- Clean and straightforward code that is easy to understand and modify for users' specific needs
Weaknesses
- Uses Sleep(3000) which blocks the EA thread and can delay processing of other symbol ticks — not a recommended practice in MQL5
- No stop-loss or risk management mechanism — if roll-over fails or contract lookup errors occur, the portfolio may be left with naked exposure
- NextFutures contract lookup logic has a flaw: it stops at the first contract with expiration beyond currtime, potentially skipping the correct next near-month contract
- Lot parameter type is int but default values contain decimal points, causing type mismatch that may lead to compilation warnings or precision loss
Possible improvements
- Remove Sleep() calls and use event-driven or timer-based approaches for roll-over operations to avoid blocking the EA thread
- Add error handling and retry mechanisms to ensure roll-over reliability, such as checking trade return values and order status
- Change Lot parameter type to double for more precise position sizing, and add maximum position limits and stop-loss parameters
Risk assessment
Overall risk: Medium
- No stop-loss mechanism — portfolio may face unhedged market risk if roll-over fails
- Sleep() blocking may cause missed critical ticks or roll-over timing
- Contract lookup logic may select the wrong month contract, resulting in positions on inappropriate contracts
Evaluation scores
Parameters
| Parameter | Default | Description |
|---|---|---|
Symbol1 | MXI | First futures symbol selection |
Symbol2 | BR | Second futures symbol selection |
Symbol3 | SBRF | Third futures symbol selection |
Lot1 | -4.0 | Lot size for first symbol (positive=long, negative=short) |
Lot2 | -1.0 | Lot size for second symbol (positive=long, negative=short) |
Lot3 | 5.0 | Lot size for third symbol (positive=long, negative=short) |
hours_before_expiration | 25 | Hours before expiration to start rollover |
Similar Hedging EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.