9.9 KiB
ForexTrader EA v3.0 - Production Grade
Overview
This repository contains production-ready Expert Advisors (EAs) for MetaTrader 5 that implement professional forex trading strategies with comprehensive risk management.
What's New in v3.0
Major Improvements
All 18 critical flaws identified in the previous versions have been fixed:
Critical Bug Fixes
- ✅ Fixed SL/TP Calculation - Removed the 10x multiplier bug that was causing stops 10x too large
- ✅ Proper MA Crossover Detection - Now correctly detects crossovers instead of sustained trends
- ✅ Fixed Tick Value Calculation - Uses SYMBOL_TRADE_TICK_VALUE_PROFIT with proper fallback
- ✅ Broker Stops Level Validation - All trades validated against broker requirements before execution
- ✅ Spread Sanity Checks - Rejects trades when spread is too high (absolute and relative to SL)
- ✅ Cooldown Mechanism - Prevents rapid re-entry after losses, with separate buy/sell cooldowns
- ✅ Trade Retry Logic - Implements intelligent retry with transient error detection
- ✅ Proper Pip Size Calculation - Correctly handles 3 and 5 digit brokers
Risk Management Enhancements
- ✅ ADX Trend Filter - Only trades during strong trends
- ✅ ATR Volatility Filter - Avoids both low volatility and spike conditions
- ✅ Max Drawdown Guard - Automatically stops trading if drawdown exceeds threshold
- ✅ MA Slope and Distance Filters - Eliminates weak crossover signals
- ✅ Daily Trade Limits - Prevents overtrading
- ✅ Portfolio Risk Management - Tracks total risk across all positions
Position Management
- ✅ Breakeven Move - Automatically moves SL to breakeven when profitable
- ✅ Smart Trailing Stop - Only activates after profit threshold reached
- ✅ Partial Take Profit - Can close portion of position at first target
Professional Features
- ✅ OnTradeTransaction Handler - Proper trade lifecycle management
- ✅ Comprehensive Error Handling - Detailed error descriptions and smart retry logic
- ✅ Modular Code Structure - Easy to test and maintain
- ✅ Input Validation - Prevents incorrect parameter settings
- ✅ Enhanced Logging - Detailed context for debugging
Available EAs
1. ForexTrader_v3_Production.mq5 (Single-Pair EA)
Best for: Traders who want to focus on one currency pair with maximum stability and control.
Key Features:
- Adaptive MA crossover strategy with multiple confirmation filters
- ADX trend strength filter
- ATR volatility range filter
- Comprehensive risk management
- Breakeven and trailing stop management
- Separate buy/sell cooldown
- Daily trade limits
Recommended Settings:
- Risk: 1.5-2% per trade
- Timeframe: M15, M30, or H1
- Pairs: Major pairs (EURUSD, GBPUSD, USDJPY)
2. ForexTrader_v3_MultiStrategy_Production.mq5 (Multi-Strategy Portfolio EA)
Best for: Experienced traders who want to diversify across multiple strategies.
Key Features:
- 4 Trading Strategies:
- Moving Average Crossover
- RSI Reversal
- Bollinger Bands Bounce
- MACD Crossover
- Signal Scoring System - Combines multiple strategies for high-probability trades
- Multi-Timeframe Analysis - Confirms trends across M15, M30, and H1
- Portfolio Risk Management - Manages total risk across all positions
- Session-Based Filters - Trade specific market sessions (London, NY, Asian)
- Dynamic Risk Adjustment - Adjusts risk based on win rate
- Strategy Performance Tracking - Monitors each strategy's effectiveness
- Partial Take Profit - Locks in profits while letting winners run
Recommended Settings:
- Risk: 1.5% per trade
- Min Signal Score: 60 (for quality entries)
- Max Concurrent Positions: 3-5
- Timeframe: M15 or M30
Installation
- Copy the desired EA file to:
MetaTrader 5/MQL5/Experts/ - Restart MetaTrader 5 or refresh the Navigator
- Drag the EA onto your chart
- Configure the input parameters
- Enable AutoTrading
Recommended Configuration
Conservative (Low Risk)
Risk Per Trade: 1.0%
Max Drawdown: 20%
Use ADX Filter: Yes
ADX Minimum: 25
Use ATR Filter: Yes
Max Concurrent Positions: 1-2
Moderate (Balanced)
Risk Per Trade: 1.5-2.0%
Max Drawdown: 25%
Use ADX Filter: Yes
ADX Minimum: 20
Use ATR Filter: Yes
Max Concurrent Positions: 3-4
Aggressive (Higher Risk/Reward)
Risk Per Trade: 2.5-3.0%
Max Drawdown: 30%
Use ADX Filter: Optional
Min Signal Score: 50 (Multi-Strategy EA)
Max Concurrent Positions: 5
Testing
Backtesting
- Open Strategy Tester (Ctrl+R)
- Select the EA
- Choose symbol and timeframe
- Set date range (minimum 6 months recommended)
- Use "Every tick" mode for accuracy
- Optimize key parameters if needed
Forward Testing
- Test on demo account first (minimum 1 month)
- Monitor performance metrics:
- Win rate
- Profit factor
- Maximum drawdown
- Average trade duration
- Adjust parameters based on results
- Only move to live when consistently profitable
Parameter Guide
Risk Management Parameters
| Parameter | Description | Default | Range |
|---|---|---|---|
| RiskPercent | Risk per trade as % of balance | 2.0 | 0.5-5.0 |
| StopLossPips | Fixed stop loss in pips | 40 | 20-100 |
| TakeProfitPips | Fixed take profit in pips | 80 | 40-200 |
| MaxDrawdownPercent | Max drawdown before halting | 30.0 | 10-50 |
| MaxSpreadPips | Maximum acceptable spread | 5.0 | 1-10 |
Filter Parameters
| Parameter | Description | Default | Range |
|---|---|---|---|
| UseADXFilter | Enable trend strength filter | Yes | - |
| ADX_Minimum | Minimum ADX value for trading | 20.0 | 15-30 |
| UseATRFilter | Enable volatility filter | Yes | - |
| ATR_MinimumPips | Minimum volatility to trade | 10.0 | 5-20 |
| ATR_MaximumPips | Maximum volatility (spike protection) | 100.0 | 50-200 |
Position Management Parameters
| Parameter | Description | Default | Range |
|---|---|---|---|
| UseBreakeven | Auto move to breakeven | Yes | - |
| BreakevenTriggerPips | Profit to trigger breakeven | 20.0 | 10-50 |
| UseTrailingStop | Enable trailing stop | Yes | - |
| TrailingStopPips | Trailing distance | 30.0 | 15-50 |
| TrailingActivationPips | Profit to activate trailing | 20.0 | 10-40 |
Performance Monitoring
Key Metrics to Watch
- Win Rate: Should be 50-70%
- Profit Factor: Should be > 1.5
- Maximum Drawdown: Should stay under your threshold
- Average Trade Duration: Should align with your timeframe
- Risk/Reward Ratio: Should be at least 1:1.5
Warning Signs
- Excessive losses: Check if market conditions changed
- High drawdown: Reduce risk or pause trading
- Low win rate (<40%): Review filter settings
- Frequent order rejections: Check spread and broker conditions
Advanced Features
Dynamic Risk Management (Multi-Strategy EA)
The multi-strategy EA can adjust risk based on recent performance:
- Win rate > 60%: Increases risk by 20%
- Win rate < 40%: Decreases risk by 20%
- Stays within MinRiskPercent and MaxRiskPercent bounds
Multi-Timeframe Analysis
When enabled, the EA requires confirmation from multiple timeframes:
- Fast TF (M15): Quick trend detection
- Medium TF (M30): Confirms trend strength
- Slow TF (H1): Validates major trend direction
Session Filters
Trade specific market sessions for optimal conditions:
- Asian Session: Lower volatility, range-bound
- London Session: High volatility, strong trends
- New York Session: Highest liquidity, best for breakouts
Troubleshooting
EA Not Trading
- Check AutoTrading is enabled (F7 key)
- Verify trading hours (if UseTradingHours enabled)
- Check if daily trade limit reached
- Verify spread is within MaxSpreadPips
- Check if ADX/ATR filters are too restrictive
- Review cooldown settings
Order Rejected
- Check broker connection
- Verify account has sufficient margin
- Check if stop levels are valid
- Review spread at time of rejection
- Check broker's minimum lot size
Poor Performance
- Optimize parameters for your broker and pair
- Check if market regime changed (trending vs ranging)
- Verify spread costs aren't too high
- Review filter settings (may be too restrictive or too loose)
- Consider different timeframe
Safety Features
All v3.0 EAs include multiple safety layers:
- Pre-trade Validation: Checks spread, stops levels, freeze levels
- Drawdown Protection: Stops trading if max drawdown reached
- Portfolio Risk Limits: Prevents over-exposure
- Error Handling: Graceful handling of all order errors
- Position Monitoring: Continuous management of open trades
Support and Updates
For issues, suggestions, or questions:
- GitHub Issues: Report here
- Review previous logs in
/Previous Logs/for development history
Credits
- Original concept and analysis: SimonFX
- Development: GitHub Copilot Agent
- Based on professional forex trading principles from included course materials
Disclaimer
IMPORTANT: Trading forex carries substantial risk. These EAs are provided for educational purposes. Always:
- Test thoroughly on demo accounts
- Never risk more than you can afford to lose
- Understand all parameters before using
- Monitor performance regularly
- Keep stop losses in place
Past performance does not guarantee future results. Use at your own risk.
Version History
v3.0 (Current)
- Complete refactoring with all critical flaws fixed
- Production-ready single-pair and multi-strategy versions
- Comprehensive risk management system
- Professional error handling and logging
v2.0
- Multi-strategy implementation (with flaws)
- Portfolio management features
v1.2
- User tuned version (with improvements but still flawed)
v1.0 (Base)
- Initial implementation (had 18+ critical flaws)
License
MIT License - See repository for details.