feat(maea): migrate from MQL4 to MQL5 and simplify strategy
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.
This commit is contained in:
@@ -1,39 +1,37 @@
|
||||
# MAEA Project Summary
|
||||
|
||||
## Project Overview
|
||||
**MAEA (Moving Average Expert Advisor)** - An advanced trend-following trading robot for MetaTrader 4 with sophisticated filtering and risk management features.
|
||||
**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 (5 Visual Lines)
|
||||
### Indicator System (2 EMA Lines + Zone)
|
||||
1. **EMA High** (Light Blue) - EMA of High prices, period 30
|
||||
2. **EMA Medium** (Yellow) - EMA of Close prices, period 30
|
||||
3. **EMA Low** (Orange) - EMA of Low prices, period 30
|
||||
4. **High Border** (Purple) - EMA High + (EMA Medium - EMA Low)
|
||||
5. **Low Border** (Purple) - EMA Low - (EMA Medium - EMA Low)
|
||||
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
|
||||
- **Sell:** Close price breaks below EMA Low
|
||||
- **Purpose:** Triggers order opening
|
||||
- **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. Pullback Signal
|
||||
- **Buy Pullback:** Price moves down to hit any line, then closes above the line
|
||||
- **Sell Pullback:** Price moves up to hit any line, then closes below the line
|
||||
- **Purpose:** Increases lot size when breakthrough occurs in same direction
|
||||
- **Tracking:** Separate for buy and sell directions
|
||||
#### 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 Order:** Only one order at a time
|
||||
- **Dynamic Lot Sizing:**
|
||||
- 0.01 lot (no pullback before breakthrough)
|
||||
- 0.02 lot (pullback occurred before breakthrough)
|
||||
- **Stop Loss:** At Border Lines (Low Border for buys, High Border for sells)
|
||||
- **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)
|
||||
@@ -42,8 +40,9 @@
|
||||
|
||||
### 1. Volume Filter
|
||||
- Calculate 20-bar volume average
|
||||
- Trade only when current volume > average
|
||||
- Ensures sufficient market activity
|
||||
- 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
|
||||
@@ -53,9 +52,9 @@
|
||||
- **Trading Timeframe:** H1
|
||||
- **Filter Timeframe:** D1
|
||||
- **Logic:**
|
||||
- D1 close > D1 EMA High: Only buy orders allowed
|
||||
- D1 close < D1 EMA Low: Only sell orders allowed
|
||||
- D1 close between: No orders allowed
|
||||
- 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)
|
||||
@@ -69,30 +68,38 @@
|
||||
- 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 MQL4 project structure
|
||||
- Create MQL5 project structure
|
||||
- Initialize Git repository
|
||||
- Configure remote to Gitea server
|
||||
|
||||
### Phase 2: Core EA Structure (4 tasks)
|
||||
- Create MAEA.mq4 with basic framework
|
||||
- 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, Medium, Low)
|
||||
- Implement Border Line calculations
|
||||
- Add visual indicators with colors
|
||||
- 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 (4 tasks)
|
||||
### Phase 4: Signal Detection (3 tasks)
|
||||
- Implement breakthrough signal detection
|
||||
- Implement pullback signal detection
|
||||
- Implement separate pullback tracking
|
||||
- Implement pullback flag reset logic
|
||||
- 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
|
||||
@@ -106,31 +113,37 @@
|
||||
- Add enable/disable toggle for news filter
|
||||
|
||||
### Phase 7: Order Management (7 tasks)
|
||||
- Implement order opening with all filters
|
||||
- Implement dynamic lot sizing
|
||||
- Implement Stop Loss placement
|
||||
- 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 order restriction
|
||||
- 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 (5 tasks)
|
||||
### 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 order closure logic
|
||||
- Implement position closure logic
|
||||
|
||||
### Phase 10: Testing & Validation (7 tasks)
|
||||
- Test all EMA and Border Line calculations
|
||||
- Test breakthrough and pullback signals
|
||||
### 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 order opening with correct lot sizes
|
||||
- Test position opening with fixed 0.01 lot
|
||||
- Test TP, SL, breakeven, and trailing stop
|
||||
- Test drawdown protection
|
||||
- Test visual indicators display
|
||||
@@ -142,44 +155,46 @@
|
||||
- Commit initial code to Git
|
||||
- Push to Gitea repository and verify
|
||||
|
||||
## Total Tasks: 50
|
||||
## Total Tasks: 51
|
||||
|
||||
## Key Features Summary
|
||||
|
||||
✅ **Advanced Trend Following:** EMA-based with dynamic border lines
|
||||
✅ **Smart Signal Detection:** Breakthrough and pullback signals with separate tracking
|
||||
✅ **Dynamic Lot Sizing:** 0.01 or 0.02 based on market behavior
|
||||
✅ **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 borders, breakeven, trailing stop
|
||||
✅ **Visual Indicators:** 5 colored lines for easy analysis
|
||||
✅ **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 Order Management:** Prevents over-trading
|
||||
✅ **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 all EMAs |
|
||||
| Lot Size (Normal) | 0.01 | Lot without pullback |
|
||||
| Lot Size (Pullback) | 0.02 | Lot with pullback |
|
||||
| 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 4
|
||||
- **Language:** MQL4
|
||||
- **Platform:** MetaTrader 5
|
||||
- **Language:** MQL5
|
||||
- **Trading Timeframe:** H1 (recommended)
|
||||
- **Filter Timeframe:** D1 (for MTF)
|
||||
- **Currency Pairs:** All pairs (user-selectable)
|
||||
- **Account Types:** Any MT4 account
|
||||
- **Account Types:** Any MT5 account
|
||||
- **Server Timezone:** Thailand (UTC+7)
|
||||
|
||||
## Next Steps
|
||||
|
||||
Reference in New Issue
Block a user