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:
Kunthawat Greethong
2026-01-03 14:25:25 +07:00
parent cd0b2e35a2
commit db575179ae
8 changed files with 1019 additions and 1243 deletions

View File

@@ -2,58 +2,44 @@
## Project Overview
- **Name**: MAEA
- **Type**: MQL4 Expert Advisor for MetaTrader 4
- **Type**: MQL5 Expert Advisor for MetaTrader 5
- **Strategy**: Advanced trend-following with EMA-based signals, multiple filters, and risk management
- **Repository**: https://git.moreminimore.com/kunthawat/MAEA
- **Timezone**: Thailand (UTC+7)
## Strategy Details
### 1. EMA Lines (3 Base Lines)
### 1. EMA Lines (2 Base Lines)
All EMAs use period 30 with different price sources:
- **EMA High**: EMA of High prices - Light Blue color
- **EMA Medium**: EMA of Close prices - Yellow color
- **EMA Low**: EMA of Low prices - Orange color
### 2. Border Lines (2 Dynamic Lines)
Calculated based on the range between EMAs:
- **High Border Line**: EMA High + (EMA Medium - EMA Low) - Purple color
- **Low Border Line**: EMA Low - (EMA Medium - EMA Low) - Purple color
### 2. EMA Zone (Visual Area)
- **Zone Definition**: The area between EMA High and EMA Low
- **Visual**: Light yellow transparent fill between EMA High and EMA Low
**Example Calculation:**
```
EMA High = 3500
EMA Medium = 3400
EMA Low = 3300
Range = EMA Medium - EMA Low = 3400 - 3300 = 100
High Border = 3500 + 100 = 3600
Low Border = 3300 - 100 = 3200
```
### 3. Signal Types
### 3. Signal Type
#### 3.1 Breakthrough Signal
- **Buy Signal**: Close price breaks above EMA High
- **Sell Signal**: Close price breaks below EMA Low
- **Purpose**: Triggers order opening
- **Buy Signal**: Close price breaks above EMA High (zone breakout upward)
- **Sell Signal**: Close price breaks below EMA Low (zone breakout downward)
- **Purpose**: Triggers position opening/closing
- **Logic**:
- Previous close must be inside zone (between EMA High and EMA Low)
- Current close must be outside zone
- For buy: previous_close <= EMA_High AND current_close > EMA_High
- For sell: previous_close >= EMA_Low AND current_close < EMA_Low
#### 3.2 Pullback Signal
- **Definition**: Price hits a line and closes on the opposite side
- **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 the same direction
- **Tracking**: Separate tracking for buy and sell directions, resets when order opens
- **Lot Size Impact**:
- No pullback before breakthrough = 0.01 lot
- Pullback occurred before breakthrough = 0.02 lot
#### 3.2 Opposite Signal Close
- **Close Buy Position**: When sell signal occurs (price breaks below EMA Low)
- **Close Sell Position**: When buy signal occurs (price breaks above EMA High)
- **Priority**: Opposite signal closes existing position immediately before opening new one
### 4. Order Opening Logic
- **Only one order at a time**
- **Lot Size**:
- 0.01 lot if no pullback occurred before breakthrough
- 0.02 lot if at least one pullback occurred before breakthrough in the same direction
- **Only one position at a time**
- **Lot Size**: Fixed 0.01 lot for all trades
- **Trigger**: Breakthrough signal only
- **Minimum Zone Width**: Zone must be at least 100 points before trading
- **Filters Applied**:
- Volume filter must pass
- Spread filter must pass
@@ -67,8 +53,8 @@ Low Border = 3300 - 100 = 3200
- Closes order when profit reaches target amount
#### 5.2 Stop Loss
- **Buy Orders**: SL at Low Border Line
- **Sell Orders**: SL at High Border Line
- **Buy Orders**: SL at EMA Low
- **Sell Orders**: SL at EMA High
#### 5.3 Breakeven
- Triggered when profit reaches specified number of points (e.g., 100 points)
@@ -90,10 +76,10 @@ Low Border = 3300 - 100 = 3200
- **Timeframes**: H1 (trading) and D1 (filter)
- **Status**: Optional feature (can be turned on/off)
- **D1 Filter Logic**:
- If D1 close > D1 EMA High: Only buy orders allowed
- If D1 close < D1 EMA Low: Only sell orders allowed
- If D1 close between D1 EMA High and D1 EMA Low: No orders allowed
- **Behavior**: Order opens immediately when filter condition is met
- If D1 close > D1 EMA High: Only buy positions allowed (bullish trend)
- If D1 close < D1 EMA Low: Only sell positions allowed (bearish trend)
- If D1 close between D1 EMA High and D1 EMA Low: No positions allowed (no clear trend)
- **Behavior**: Position opens immediately when filter condition is met
### 8. Spread Filter
- **Purpose**: Avoid trading during high spread periods
@@ -115,80 +101,83 @@ Low Border = 3300 - 100 = 3200
```mermaid
graph TD
A[Start New Bar] --> B[Calculate EMAs]
B --> C[Calculate Border Lines]
C --> D[Check for Open Orders]
D -->|Has Open Order| E[Manage Open Order]
D -->|No Open Order| F[Check Pullback Signals]
A[Start New Bar] --> B[Calculate EMA High/Low]
B --> C[Fill Zone Between EMAs]
C --> D[Check for Open Positions]
D -->|Has Open Position| E[Check Opposite Signal]
D -->|No Open Position| F[Check Breakthrough Signals]
E --> E1[Check Take Profit]
E1 -->|TP Reached| E2[Close Order]
E1 -->|TP Not Reached| E3[Check Breakeven]
E3 -->|Breakeven Reached| E4[Move SL to Entry]
E3 -->|Breakeven Not Reached| E5[Check Stop Loss]
E5 -->|SL Hit| E2
E5 -->|SL Not Hit| A
E --> E1{Opposite Signal?}
E1 -->|Buy open, Sell signal| E2[Close Buy Position]
E1 -->|Sell open, Buy signal| E3[Close Sell Position]
E1 -->|No opposite signal| E4[Manage Position Risks]
E2 --> A
E3 --> A
F --> F1[Close Below EMA High]
F1 -->|Yes| F2[Set Pullback Flag]
F1 -->|No| F3[Close Below EMA Medium]
F3 -->|Yes| F2
F3 -->|No| F4[Close Below EMA Low]
F4 -->|Yes| F2
F4 -->|No| F5[Check Breakthrough Signals]
E4 --> E5[Check Take Profit]
E5 -->|TP Reached| E6[Close Position]
E5 -->|TP Not Reached| E7[Check Breakeven]
E7 -->|Breakeven Reached| E8[Move SL to Entry]
E7 -->|Breakeven Not Reached| E9[Check SL Hit]
E9 -->|SL Hit| E6
E9 -->|SL Not Hit| A
E6 --> A
F2 --> F5
F5 --> F6[Close Above EMA High]
F6 -->|Yes| F7[Open Buy Order]
F6 -->|No| F8[Close Below EMA Low]
F8 -->|Yes| F9[Open Sell Order]
F8 -->|No| A
F --> F1{Previous Close Inside Zone?}
F1 -->|No| A
F1 -->|Yes| F2{Zone Width >= 100 points?}
F2 -->|No| A
F2 -->|Yes| F3{Current Close Direction}
F3 -->|Close > EMA High| F4[Check Filters]
F3 -->|Close < EMA Low| F5[Check Filters]
F3 -->|Still Inside| A
F7 --> F10[Set Lot Size]
F10 -->|Pullback| F11[0.02 Lot]
F10 -->|No Pullback| F12[0.01 Lot]
F11 --> F13[Set SL at Low Border]
F12 --> F13
F13 --> F14[Set TP based on USD Target]
F14 --> F15[Reset Pullback Flag]
F15 --> A
F4 --> F6{Volume OK? Spread OK? MTF OK? News OK?}
F5 --> F6
F6 -->|All Pass| F7[Open Buy Position]
F6 -->|Any Fail| A
F9 --> F16[Set Lot Size]
F16 -->|Pullback| F17[0.02 Lot]
F16 -->|No Pullback| F18[0.01 Lot]
F17 --> F19[Set SL at High Border]
F18 --> F19
F19 --> F20[Set TP based on USD Target]
F20 --> F21[Reset Pullback Flag]
F21 --> A
F7 --> F8[Set SL at EMA Low]
F8 --> F9[Set TP based on USD Target]
F9 --> A
E2 --> F15
F5 --> F10{Volume OK? Spread OK? MTF OK? News OK?}
F10 -->|All Pass| F11[Open Sell Position]
F10 -->|Any Fail| A
F11 --> F12[Set SL at EMA High]
F12 --> F13[Set TP based on USD Target]
F13 --> A
```
## Implementation Steps
### Phase 1: Project Setup & Git Configuration
1. Create MQL4 project structure
1. Create MQL5 project structure
2. Initialize Git repository
3. Configure remote to Gitea server (https://git.moreminimore.com/kunthawat/MAEA)
### Phase 2: Core EA Structure
4. Create [`MAEA.mq4`](MAEA.mq4) with basic EA framework
5. Define all input parameters (EMA period, lot sizes, TP, breakeven, trailing stop, filters, etc.)
6. Set up indicator buffers for 5 visual lines
4. Create [`MAEA.mq5`](MAEA.mq5) with basic EA framework
5. Define all input parameters (EMA period, lot size, TP, breakeven, trailing stop, filters, etc.)
6. Set up indicator buffers for 2 EMA lines + zone fill (3 buffers total)
7. Initialize global variables for state tracking
### Phase 3: Indicator Calculations
8. Implement EMA calculations for High, Medium, Low (period 30)
9. Implement Border Line calculations (High Border = High + Range, Low Border = Low - Range)
10. Add visual indicators with correct colors (Light Blue, Yellow, Orange, Purple)
8. Implement EMA calculations for High and Low (period 30)
9. Implement zone fill between EMA High and EMA Low (transparent light yellow)
10. Add visual indicators with correct colors (Light Blue for EMA High, Orange for EMA Low)
11. Implement Volume average calculation (20-bar average)
### Phase 4: Signal Detection
12. Implement breakthrough signal detection (price breaks High/Low EMA)
13. Implement pullback signal detection (price hits line and closes on opposite side)
14. Implement separate pullback tracking for buy and sell directions
15. Implement pullback flag reset logic after order opens
12. Implement breakthrough signal detection
- Check if previous close was inside zone
- Check if current close broke above EMA High or below EMA Low
13. Implement opposite signal detection and position closing
- If buy position open and sell signal occurs: close buy
- If sell position open and buy signal occurs: close sell
14. Implement minimum zone width check (100 points)
15. Implement single position check
### Phase 5: Multiple Timeframe Filter
16. Implement D1 EMA calculations for MTF filter
@@ -202,13 +191,15 @@ graph TD
22. Add enable/disable toggles for news filter
### Phase 7: Order Management
23. Implement order opening logic with all filter checks
24. Implement dynamic lot sizing (0.01 no pullback, 0.02 with pullback)
25. Implement Stop Loss placement at Border Lines
23. Implement position opening logic with all filter checks
24. Implement fixed lot sizing (0.01 lot)
25. Implement Stop Loss placement at opposite EMA
- Buy: SL at EMA Low
- Sell: SL at EMA High
26. Implement Take Profit calculation (convert USD target to pips)
27. Implement Breakeven logic (move SL to entry at X points)
28. Implement Trailing Stop logic (trail by X points after breakeven)
29. Implement single order restriction
29. Implement single position restriction (use PositionsTotal())
### Phase 8: Risk Management
30. Implement max drawdown calculation
@@ -216,20 +207,24 @@ graph TD
32. Implement trading resume logic when drawdown is below limit
### Phase 9: Order Monitoring & Management
33. Implement Take Profit checking on each tick
34. Implement Breakeven checking and SL modification
35. Implement Trailing Stop checking and SL modification
36. Implement Stop Loss checking
37. Implement order closure logic
33. Implement opposite signal checking on each tick
34. If opposite signal detected, close existing position immediately
35. Implement Take Profit checking on each tick
36. Implement Breakeven checking and SL modification
37. Implement Trailing Stop checking and SL modification
38. Implement Stop Loss checking
39. Implement position closure logic
### Phase 10: Testing & Validation
38. Test all EMA and Border Line calculations
39. Test breakthrough and pullback signal detection
40. Test all filters (volume, spread, MTF, news)
41. Test order opening with correct lot sizes
42. Test TP, SL, breakeven, and trailing stop
43. Test drawdown protection
44. Test visual indicators display
38. Test EMA High and Low calculations
39. Test zone fill visualization (transparent yellow)
40. Test breakthrough signal detection
- Verify breakout requires previous close inside zone
41. Test all filters (volume, spread, MTF, news)
42. Test position opening with fixed 0.01 lot
43. Test TP, SL (at opposite EMA), breakeven, and trailing stop
44. Test drawdown protection
45. Test visual indicators display
### Phase 11: Documentation & Deployment
45. Create comprehensive [`README.md`](README.md) with strategy documentation
@@ -243,15 +238,15 @@ graph TD
| Parameter | Description | Default Value |
|-----------|-------------|---------------|
| `EMAPeriod` | EMA period for all lines | 30 |
| `LotSizeNormal` | Lot size without pullback | 0.01 |
| `LotSizePullback` | Lot size with pullback | 0.02 |
| `EMAPeriod` | EMA period for both lines | 30 |
| `LotSize` | Fixed lot size | 0.01 |
| `TakeProfitUSD` | Take profit target in USD | 5.0 |
| `BreakevenPoints` | Points to trigger breakeven | 100 |
| `TrailingStopPoints` | Points for trailing stop distance | 100 |
| `MagicNumber` | EA unique identifier | 12345 |
| `MaxSpread` | Maximum allowed spread in points | 30 |
| `VolumePeriod` | Period for volume average calculation | 20 |
| `MinZoneWidthPoints` | Minimum zone width to trade (points) | 100 |
| `MaxDrawdownPercent` | Maximum drawdown percentage | 10.0 |
| `UseMTFFilter` | Enable/disable MTF filter | true |
| `UseNewsFilter` | Enable/disable news filter | true |
@@ -263,61 +258,73 @@ graph TD
| Line | Color | Description |
|------|-------|-------------|
| EMA High | Light Blue (clrLightBlue) | EMA of High prices |
| EMA Medium | Yellow (clrYellow) | EMA of Close prices |
| EMA Low | Orange (clrOrange) | EMA of Low prices |
| High Border | Purple (clrPurple) | Upper dynamic border |
| Low Border | Purple (clrPurple) | Lower dynamic border |
| Zone Fill | Light Yellow (transparent) | Area between EMA High and EMA Low |
## Key Considerations
1. **Pullback Detection**: Track price hitting lines and closing on opposite side separately for buy/sell
2. **Pullback Reset**: Reset pullback flag immediately after opening an order
3. **Single Order**: Only one order open at any time
4. **Dynamic SL**: Stop Loss moves with Border Lines as they update
5. **Breakeven**: Only moves SL to entry price, not to profit
6. **TP Calculation**: Convert USD target to pips based on lot size and symbol
7. **Volume Filter**: Only trade when current volume exceeds 20-bar average
8. **MTF Filter**: D1 timeframe acts as trend filter, H1 for entry signals
9. **Spread Filter**: Avoid high spread periods
10. **Timezone**: All time-based filters use Thailand timezone (UTC+7)
11. **Trailing Stop**: Activates after breakeven, trails by specified points
12. **Drawdown Protection**: Stops trading if max drawdown exceeded
1. **Breakthrough Detection**: Previous close must be inside zone, current close outside zone
2. **Opposite Signal Close**: Close existing position when opposite breakthrough signal occurs
3. **Minimum Zone Width**: Zone must be at least 100 points wide before trading
4. **Single Position**: Only one position open at any time (MT5 uses positions, not orders)
5. **SL at Opposite EMA**: Buy SL at EMA Low, Sell SL at EMA High
6. **Fixed Lot Size**: Always 0.01 lot regardless of market conditions
7. **Breakeven**: Only moves SL to entry price, not to profit
8. **TP Calculation**: Convert USD target to pips based on lot size and symbol
9. **Volume Filter**: Only trade when current volume exceeds 20-bar average
10. **MTF Filter**: D1 price position relative to zone determines allowed direction
11. **Spread Filter**: Avoid high spread periods
12. **Timezone**: All time-based filters use Thailand timezone (UTC+7)
13. **Trailing Stop**: Activates after breakeven, trails by specified points
14. **Drawdown Protection**: Stops trading if max drawdown exceeded
15. **Zone Visualization**: Light yellow transparent fill between EMA High and EMA Low
## Technical Specifications
- **Platform**: MetaTrader 4
- **Language**: MQL4
- **Platform**: MetaTrader 5
- **Language**: MQL5
- **Trading Timeframe**: H1 (recommended)
- **Filter Timeframe**: D1 (for MTF filter)
- **Currency Pairs**: All pairs (user-selectable)
- **Account Types**: Any MT4 account type
- **Account Types**: Any MT5 account type
- **Server Timezone**: Thailand (UTC+7)
## Testing Checklist
### Core Strategy
- [ ] EMA calculations verify correctly (High, Medium, Low)
- [ ] Border Line calculations verify correctly
- [ ] EMA calculations verify correctly (High and Low)
- [ ] Zone fill displays correctly (light yellow, transparent)
- [ ] Zone width calculation verify correctly (in points)
- [ ] Minimum zone width filter works (100 points minimum)
- [ ] Breakthrough signals trigger correctly
- [ ] Pullback signals detect correctly (buy and sell separately)
- [ ] Pullback flag resets after order opens
- [ ] Lot sizes apply correctly (0.01 vs 0.02)
- [ ] Previous close inside zone check
- [ ] Buy signal: close > EMA High
- [ ] Sell signal: close < EMA Low
- [ ] Opposite signal detection works
- [ ] Buy position closes when sell signal occurs
- [ ] Sell position closes when buy signal occurs
### Filters
- [ ] Volume filter works (20-bar average, current > average)
- [ ] Spread filter prevents high spread trades
- [ ] MTF filter works correctly (D1 > High = buy only, D1 < Low = sell only, between = no trade)
- [ ] MTF filter works correctly
- [ ] D1 close > EMA High: buy only
- [ ] D1 close < EMA Low: sell only
- [ ] D1 close between: no trade
- [ ] MTF filter can be enabled/disabled
- [ ] Min zone width filter works (100 points minimum)
- [ ] News filter avoids specified times (Thailand timezone)
- [ ] News filter can be enabled/disabled
### Order Management
- [ ] Stop Loss places at correct Border Lines
- [ ] Stop Loss places at opposite EMA (Buy: EMA Low, Sell: EMA High)
- [ ] Take Profit closes at correct USD amount
- [ ] Breakeven triggers at correct points
- [ ] Trailing stop activates after breakeven
- [ ] Trailing stop trails by correct distance
- [ ] Only one order opens at a time
- [ ] Opposite signal closes existing position immediately
- [ ] Only one position opens at a time
- [ ] Fixed lot size always 0.01
### Risk Management
- [ ] Max drawdown protection works
@@ -332,11 +339,15 @@ graph TD
## Notes
- The strategy uses 5 visual lines on the chart
- Pullback tracking is separate for buy and sell directions
- Border Lines expand the range beyond the EMAs for wider stops
- The strategy uses 2 EMA lines with a filled zone between them
- No pullback tracking or dynamic lot sizing - simplified approach
- Fixed lot size: 0.01 for all trades
- Positions close when opposite signal occurs (reversal protection)
- Minimum zone width of 100 points ensures meaningful setups
- The strategy is trend-following and works best in trending markets
- Breakthrough signals require price to be inside zone before breaking out
- Multiple filters ensure quality trade entries
- All time-based calculations use Thailand timezone (UTC+7)
- MTF filter provides higher timeframe trend confirmation
- Risk management features protect account from excessive losses
- MTF filter matches price position relative to D1 zone
- Risk management features protect account from excessive losses
- Zone fill uses light yellow color with transparency for better visibility

View File

@@ -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