Migrate MAEA Expert Advisor from MetaTrader 4 to MetaTrader 5 platform with significant strategy simplification and architectural improvements. Key changes: - Platform: MQL4 → MQL5 - Indicators: Reduced from 5 lines (3 EMAs + 2 borders) to 2 EMAs with zone fill - Strategy: Removed pullback signals and dynamic lot sizing - Lot sizing: Changed from dynamic (0.01/0.02) to fixed 0.01 lot - Stop loss: Changed from Border Lines to opposite EMA (Buy: EMA Low, Sell: EMA High) - Signal logic: Added opposite signal close for reversal protection - New filter: Added minimum zone width filter (100 points) - Documentation: Updated implementation plans and project summary - New files: Added AGENTS.md, MAEA_Indicator.mq5, and opencode.jsonc BREAKING CHANGE: Complete rewrite from MQL4 to MQL5 with simplified strategy. Previous MAEA.mq4 and README.md deleted. New implementation requires MetaTrader 5.
211 lines
7.7 KiB
Markdown
211 lines
7.7 KiB
Markdown
# MAEA Project Summary
|
|
|
|
## Project Overview
|
|
**MAEA (Moving Average Expert Advisor)** - An advanced trend-following trading robot for MetaTrader 5 with sophisticated filtering and risk management features.
|
|
|
|
**Repository:** https://git.moreminimore.com/kunthawat/MAEA
|
|
**Timezone:** Thailand (UTC+7)
|
|
|
|
## Core Strategy
|
|
|
|
### Indicator System (2 EMA Lines + Zone)
|
|
1. **EMA High** (Light Blue) - EMA of High prices, period 30
|
|
2. **EMA Low** (Orange) - EMA of Low prices, period 30
|
|
3. **Zone Fill** (Light Yellow, transparent) - Area between EMA High and EMA Low
|
|
|
|
### Signal Types
|
|
|
|
#### 1. Breakthrough Signal
|
|
- **Buy:** Close price breaks above EMA High (must have previous close inside zone)
|
|
- **Sell:** Close price breaks below EMA Low (must have previous close inside zone)
|
|
- **Purpose:** Triggers position opening
|
|
- **Verification:** Previous bar close must be inside zone between EMA High and EMA Low
|
|
|
|
#### 2. Opposite Signal Close
|
|
- **Close Buy:** When sell signal occurs (price breaks below EMA Low)
|
|
- **Close Sell:** When buy signal occurs (price breaks above EMA High)
|
|
- **Immediate Action:** Position closes before checking for new trade
|
|
|
|
### Order Management
|
|
- **Single Position:** Only one position open at a time (MT5 uses positions, not orders)
|
|
- **Fixed Lot Size:** 0.01 lot for all trades
|
|
- **Stop Loss:** At opposite EMA (Buy: EMA Low, Sell: EMA High)
|
|
- **Reverse Protection:** Close position when opposite signal occurs
|
|
- **Min Zone Width:** Zone must be at least 100 points to trade
|
|
- **Take Profit:** Target in USD (default $5)
|
|
- **Breakeven:** Move SL to entry at X points profit (default 100)
|
|
- **Trailing Stop:** Trail by X points after breakeven (default 100)
|
|
|
|
## Advanced Filters
|
|
|
|
### 1. Volume Filter
|
|
- Calculate 20-bar volume average
|
|
- Trade only when current volume > average
|
|
- Ensures sufficient market activity
|
|
- Note: MT5 uses tick volume by default (similar to MT4)
|
|
|
|
### 2. Spread Filter
|
|
- Maximum allowed spread: 30 points
|
|
- Prevents trading during high spread periods
|
|
|
|
### 3. Multiple Timeframe (MTF) Filter (Optional)
|
|
- **Trading Timeframe:** H1
|
|
- **Filter Timeframe:** D1
|
|
- **Logic:**
|
|
- D1 close > D1 EMA High: Only buy positions allowed (bullish)
|
|
- D1 close < D1 EMA Low: Only sell positions allowed (bearish)
|
|
- D1 close between: No positions allowed (no trend)
|
|
- Can be enabled/disabled
|
|
|
|
### 4. News Filter (Optional)
|
|
- Avoid specific hours (default: 14, 15, 20, 21)
|
|
- Avoid specific days (default: 1, 5)
|
|
- All times in Thailand timezone (UTC+7)
|
|
- Can be enabled/disabled
|
|
|
|
### 5. Risk Management
|
|
- **Max Drawdown:** Percentage-based protection (default 10%)
|
|
- Stops trading if drawdown exceeds limit
|
|
- Resumes trading when drawdown is below limit
|
|
|
|
### 6. Zone Width Filter
|
|
- **Min Zone Width:** 100 points minimum before trading
|
|
- Ensures meaningful trend setups
|
|
- Prevents trading during tight consolidation
|
|
|
|
## Implementation Phases
|
|
|
|
### Phase 1: Project Setup & Git Configuration (3 tasks)
|
|
- Create MQL5 project structure
|
|
- Initialize Git repository
|
|
- Configure remote to Gitea server
|
|
|
|
### Phase 2: Core EA Structure (4 tasks)
|
|
- Create MAEA.mq5 with basic framework
|
|
- Define all input parameters
|
|
- Set up indicator buffers
|
|
- Initialize global variables
|
|
|
|
### Phase 3: Indicator Calculations (4 tasks)
|
|
- Implement EMA calculations (High and Low only)
|
|
- Implement zone fill between EMA High and EMA Low
|
|
- Add visual indicators with colors (Light Blue, Orange, Light Yellow fill)
|
|
- Implement Volume average calculation
|
|
|
|
### Phase 4: Signal Detection (3 tasks)
|
|
- Implement breakthrough signal detection
|
|
- Check if previous close inside zone
|
|
- Check if current close broke above EMA High or below EMA Low
|
|
- Implement opposite signal detection and position closing
|
|
- Close buy position when sell signal occurs
|
|
- Close sell position when buy signal occurs
|
|
- Implement minimum zone width check (100 points)
|
|
|
|
### Phase 5: Multiple Timeframe Filter (3 tasks)
|
|
- Implement D1 EMA calculations
|
|
- Implement MTF filter logic
|
|
- Add enable/disable toggle
|
|
|
|
### Phase 6: Additional Filters (4 tasks)
|
|
- Implement volume filter
|
|
- Implement spread filter
|
|
- Implement news filter (Thailand timezone)
|
|
- Add enable/disable toggle for news filter
|
|
|
|
### Phase 7: Order Management (7 tasks)
|
|
- Implement position opening with all filters
|
|
- Implement fixed lot sizing (0.01 lot)
|
|
- Implement Stop Loss placement at opposite EMA
|
|
- Implement Take Profit calculation
|
|
- Implement Breakeven logic
|
|
- Implement Trailing Stop logic
|
|
- Implement single position restriction
|
|
|
|
### Phase 8: Risk Management (3 tasks)
|
|
- Implement max drawdown calculation
|
|
- Implement drawdown protection
|
|
- Implement trading resume logic
|
|
|
|
### Phase 9: Order Monitoring & Management (6 tasks)
|
|
- Implement opposite signal checking on each tick
|
|
- Close position when opposite signal detected
|
|
- Implement Take Profit checking
|
|
- Implement Breakeven checking and SL modification
|
|
- Implement Trailing Stop checking and SL modification
|
|
- Implement Stop Loss checking
|
|
- Implement position closure logic
|
|
|
|
### Phase 10: Testing & Validation (8 tasks)
|
|
- Test EMA High and Low calculations
|
|
- Test zone fill visualization
|
|
- Test zone width calculation
|
|
- Test minimum zone width filter (100 points)
|
|
- Test breakthrough signal detection (with zone check)
|
|
- Test opposite signal detection and position closing
|
|
- Test all filters
|
|
- Test position opening with fixed 0.01 lot
|
|
- Test TP, SL, breakeven, and trailing stop
|
|
- Test drawdown protection
|
|
- Test visual indicators display
|
|
|
|
### Phase 11: Documentation & Deployment (5 tasks)
|
|
- Create comprehensive README.md
|
|
- Add parameter descriptions and usage instructions
|
|
- Add troubleshooting guide
|
|
- Commit initial code to Git
|
|
- Push to Gitea repository and verify
|
|
|
|
## Total Tasks: 51
|
|
|
|
## Key Features Summary
|
|
|
|
✅ **Simple Trend Following:** EMA-based with visual zone fill
|
|
✅ **Clear Breakthrough Signals:** Zone breakout with previous bar confirmation
|
|
✅ **Reverse Protection:** Positions close when opposite signal occurs
|
|
✅ **Minimum Zone Width:** 100 points requirement for meaningful setups
|
|
✅ **Fixed Lot Size:** Consistent 0.01 lot position sizing
|
|
✅ **Comprehensive Filters:** Volume, spread, MTF, news, and drawdown protection
|
|
✅ **Risk Management:** TP in USD, SL at opposite EMA, breakeven, trailing stop
|
|
✅ **Visual Indicators:** 2 EMAs with light yellow zone fill
|
|
✅ **Flexible Configuration:** All features can be enabled/disabled
|
|
✅ **Single Position Management:** Prevents over-trading
|
|
✅ **Timezone Aware:** Thailand timezone (UTC+7) for all time-based features
|
|
|
|
## Default Parameters
|
|
|
|
| Parameter | Value | Description |
|
|
|-----------|-------|-------------|
|
|
| EMA Period | 30 | Period for EMA High and EMA Low |
|
|
| Lot Size | 0.01 | Fixed lot size for all trades |
|
|
| Take Profit | $5 | Target profit in USD |
|
|
| Breakeven Points | 100 | Points to trigger breakeven |
|
|
| Trailing Stop Points | 100 | Trail distance after breakeven |
|
|
| Max Spread | 30 points | Maximum allowed spread |
|
|
| Volume Period | 20 | Bars for volume average |
|
|
| Min Zone Width | 100 points | Minimum zone width to trade |
|
|
| Max Drawdown | 10% | Maximum drawdown percentage |
|
|
| MTF Filter | true | Enable/disable MTF filter |
|
|
| News Filter | true | Enable/disable news filter |
|
|
|
|
## Technical Specifications
|
|
|
|
- **Platform:** MetaTrader 5
|
|
- **Language:** MQL5
|
|
- **Trading Timeframe:** H1 (recommended)
|
|
- **Filter Timeframe:** D1 (for MTF)
|
|
- **Currency Pairs:** All pairs (user-selectable)
|
|
- **Account Types:** Any MT5 account
|
|
- **Server Timezone:** Thailand (UTC+7)
|
|
|
|
## Next Steps
|
|
|
|
The implementation plan is complete and ready for execution. All 50 tasks have been clearly defined and organized into 11 logical phases. The plan includes:
|
|
|
|
1. ✅ Detailed strategy documentation
|
|
2. ✅ Visual flow diagram
|
|
3. ✅ Complete implementation steps
|
|
4. ✅ Input parameters table
|
|
5. ✅ Testing checklist
|
|
6. ✅ Technical specifications
|
|
|
|
**Ready to proceed with implementation in Code mode.** |