Specification
I need a fully automated Expert Advisor (EA) written in MQL5 for MetaTrader 5.
The EA must work directly inside MT5 and must NOT require TradingView, PineConnector, webhooks, or another external connector to place trades.
Trading Instrument
- Primary symbol: XAGUSD (Silver)
- My broker may display the symbol as XAGUSD-ECN, so the EA should work with the broker’s available XAGUSD symbol.
- Main entry timeframe: 5-minute (M5)
- Use 1-hour (H1) and 4-hour (H4) timeframes for market direction/confirmation.
Trading Direction
The EA must be able to automatically take both BUY and SELL trades.
BUY Strategy
I want a support/resistance breakout-and-retest strategy.
For BUY trades:
- Identify important resistance automatically.
- Wait for price to break above resistance.
- Confirm the breakout using a closed candle. Do not enter based only on a wick.
- Wait for price to retest the broken resistance area.
- Require bullish confirmation after the retest.
- Enter a BUY automatically when all conditions are met.
SELL Strategy
For SELL trades:
- Identify important support automatically.
- Wait for price to break below support.
- Confirm the breakout using a closed candle. Do not enter based only on a wick.
- Wait for price to retest the broken support area.
- Require bearish confirmation after the retest.
- Enter a SELL automatically when all conditions are met.
Trend Filters
- Use EMA 50 and EMA 200.
- Use H1 and H4 market direction as higher-timeframe confirmation.
- Avoid taking trades strongly against the higher-timeframe trend.
Risk Management
All of these settings must be adjustable in the EA inputs:
- Default lot size: 0.04
- Automatic Stop Loss on EVERY trade.
- Automatic Take Profit on EVERY trade.
- Default risk-to-reward ratio: 1:2.
- Maximum trades per day: 6.
- Maximum consecutive losses: 4.
- After 4 consecutive losses, STOP opening new trades for the rest of that trading day.
- The consecutive-loss counter should automatically reset for the next trading day.
- Cooldown period between trades.
- Only one active setup/trade at a time.
- Do not repeatedly trade the same breakout level.
Additional Filters
- ATR-based breakout/retest tolerance.
- Consolidation/ranging-market filter.
- Avoid weak breakouts.
- Require candle-close confirmation before entry.
- Prevent duplicate entries.
- Spread protection so the EA does not enter when spread is abnormally high.
EA Controls
I want input settings that allow me to change:
- Lot size
- Risk/reward ratio
- Maximum trades per day
- Maximum consecutive losses
- BUY trades ON/OFF
- SELL trades ON/OFF
- EMA settings
- ATR settings
- Stop Loss settings
- Take Profit settings
- Trading hours
- Maximum spread
- Higher-timeframe filters
- Cooldown period
Trade Management
Every trade opened by the EA must:
- Have a Stop Loss.
- Have a Take Profit.
- Be clearly identifiable as a trade opened by the EA.
- Use a unique Magic Number.
- Follow the selected lot size and risk-management settings.
- Prevent accidental duplicate orders.
The EA should manage BUY and SELL positions automatically without requiring me to manually confirm trades.
Testing
The EA must:
- Compile in MetaEditor with ZERO errors.
- Work correctly with the MT5 Strategy Tester.
- Be suitable for both demo testing and live MT5 accounts.
- Provide clear Journal/log messages explaining why a trade was entered or rejected.
- Include a Magic Number so I can identify trades opened by this EA.
I want the developer to test both BUY and SELL functionality.
Files I Need
Please provide:
- The complete MQL5 source code (.mq5).
- The compiled Expert Advisor (.ex5).
- Instructions explaining how to install the EA in MT5.
- Instructions explaining every adjustable input.
- Instructions explaining how to turn automatic trading ON/OFF.
I MUST receive the .mq5 source code so I can modify the EA in the future.
Before final delivery, please demonstrate that the EA works in the MT5 Strategy Tester and explain all adjustable settings.
The final EA should be completely independent and capable of analyzing XAGUSD, identifying qualifying setups, opening BUY or SELL positions, setting SL/TP, and managing its own trades directly through MetaTrader 5.