Professional-grade Expert Advisor implementing a sophisticated pyramid trading strategy for XAUUSD (Gold) on the M1 timeframe.
Grid Pyramid EA is a fully-automated trading system that:
- Places pending Buy/Sell pairs around current price
- Pyramids positions at fixed price steps when one side triggers
- Manages all positions as a unified basket
- Closes the entire basket when exit conditions are met
- Automatically re-places new pending pairs after reset
- ✅ Two-Sided Entry System: Configurable Stop or Limit pending orders
- ✅ Smart Pyramiding: Fixed USD-based price steps (≈6 pips for XAUUSD)
- ✅ Flexible Lot Sizing: Arithmetic or Geometric progression
- ✅ Basket Management: Unified exit for all positions
- ✅ Intelligent Spacing: Time/Bar/Pip-based order placement control
- 🎯 Virtual TP/SL: Hidden from broker to prevent stop hunting
- 📈 Trailing Stop: Lock in profits with configurable trailing logic
- ⏰ Trading Sessions: Filter trading hours for optimal performance
- 🛡️ Drawdown Reduction (DDR): Dynamic loss mitigation system
- 🎛️ Interactive Trade Panel: Real-time monitoring and control
- 📝 Comprehensive Logging: Timestamped actions with error handling
- 🔒 Position Limits: Max layers per side and total lots
- 💰 Multiple Exit Modes: Profit, Time, Combined (OR/AND)
- 🚨 Emergency Controls: Instant basket closure and trading halt
- 📊 Real-Time P/L: Live profit/loss tracking
| File | Description |
|---|---|
GridPyramidEA.mq4 |
Full MQL4 source code |
GridPyramidEA.ex4 |
Compiled executable (generated after compilation) |
GridPyramidEA_Default.set |
Default parameter preset |
USER_GUIDE.md |
Comprehensive user documentation |
TEST_INSTRUCTIONS.md |
Detailed testing procedures |
README.md |
This file |
-
Copy Files
GridPyramidEA.mq4 → MT4/MQL4/Experts/ GridPyramidEA_Default.set → MT4/MQL4/Presets/ -
Compile
- Open MetaEditor (F4 in MT4)
- Open
GridPyramidEA.mq4 - Press F7 to compile
- Verify "0 errors" in output
-
Attach to Chart
- Open XAUUSD M1 chart
- Drag EA from Navigator
- Enable "Allow live trading"
- Load
GridPyramidEA_Default.setpreset - Click OK
Platform: MT4 (MQL4)
Symbol: XAUUSD
Timeframe: M1 (1 Minute)
Magic Number: 222222
Entry Distance: $1.50
Price Step (Buy): $0.62 (≈6 pips)
Price Step (Sell): $0.68 (≈6 pips)
First Lot: 0.02
Lot Mode: Arithmetic
Lot Step: 0.02
Max Adds: 20 layers
Max Total Lots: 10.0
Basket TP: $100
Exit Mode: Profit
Price: 2650.00
├── BuyStop: 2651.50 (+$1.50)
└── SellStop: 2648.50 (-$1.50)
Price hits BuyStop → Basket Direction: BUY
├── Layer 1: 0.02 lots @ 2651.50
├── Layer 2: 0.04 lots @ 2652.12 (+$0.62)
├── Layer 3: 0.06 lots @ 2652.74 (+$0.62)
└── Layer 4: 0.08 lots @ 2653.36 (+$0.62)
Basket P/L reaches $100 → Close All Positions
├── Close Layer 1, 2, 3, 4
├── Cancel opposite pendings
└── Wait 30 seconds (spacing)
└── Place new BuyStop/SellStop pair
The interactive control panel provides:
Status Display
- Current EA state
- Active basket direction
- Real-time P/L
- Pyramid layers count
- Total lot exposure
Control Buttons
- START/STOP TRADING
- PAUSE/RESUME ADDS
- CLOSE ONLY MODE
- CLOSE BASKET
- EMERGENCY CLOSE ALL
- REFRESH PENDINGS
Account: $1,000+
Risk: Low
Expected Monthly: 5-10%
Max Drawdown: <15%
Account: $5,000+
Risk: Medium
Expected Monthly: 10-20%
Max Drawdown: <25%
Account: $10,000+
Risk: High
Expected Monthly: 20-40%
Max Drawdown: <40%
Past performance does not guarantee future results
Symbol: XAUUSD
Period: M1
Model: Every tick (most accurate)
Date Range: 3 months minimum
Initial Deposit: $1,000+
Target Metrics:
- Profit Factor: > 1.2
- Win Rate: > 50%
- Max Drawdown: < 30%
- Attach to demo XAUUSD M1 chart
- Monitor for 1-2 weeks
- Verify:
- Correct order placement
- Accurate pyramiding
- Basket exit at target
- Panel accuracy
See TEST_INSTRUCTIONS.md for detailed procedures.
| Document | Purpose |
|---|---|
| USER_GUIDE.md | Complete parameter reference, setup, usage examples |
| TEST_INSTRUCTIONS.md | Backtesting, visual testing, validation procedures |
- Magic Number
- First Lot Size
- Slippage Tolerance
- Order Type (Stop/Limit)
- Entry Distance from Price
- Price Steps (Buy/Sell)
- Lot Mode (Arithmetic/Geometric)
- Lot Progression Settings
- Position Limits
- Exit Mode (Profit/Time/Combined)
- Profit Target (USD)
- Time Limits
- Mode (Time/Bar/Pip)
- Minimum Spacing Values
- Virtual TP/SL
- Trailing Stop
- Session Filter
- DDR (Drawdown Reduction)
- Trade Panel Display
- Colors and Positioning
The EA provides detailed logging:
[2025-11-05 10:15:23] EA Initialized - Magic: 222222, Symbol: XAUUSD
[2025-11-05 10:15:25] Initial pending pair placed: Buy #12345, Sell #12346
[2025-11-05 10:18:42] Pyramid buy added: Layer 2, Ticket #12347
[2025-11-05 10:22:15] Basket exit triggered: Profit target reached: 105.50 USD
[2025-11-05 10:22:18] Basket closed - Final profit: 105.50 USD
IMPORTANT: Trading forex and CFDs involves substantial risk of loss. This EA is provided for educational purposes. Key points:
⚠️ Never risk more than you can afford to lose⚠️ Always test on demo accounts first⚠️ Past performance ≠ future results⚠️ Monitor EA performance regularly⚠️ Use appropriate risk management⚠️ Understand all parameters before live trading
- MT4 Build 1090+
- Windows 7+ / Wine (Linux/Mac)
- 2GB RAM
- Stable internet connection
- MT4 Latest Build
- Windows 10/11
- 4GB+ RAM
- VPS with <10ms broker latency
- Broker with low spreads (<30 pips XAUUSD)
✅ Required:
- Allows Expert Advisors
- XAUUSD symbol available
- Sufficient leverage (1:100+)
- Acceptable spreads
✅ Preferred:
- ECN/STP execution
- No requotes
- Fast order execution
- 24/5 support
- Check "Allow live trading" enabled
- Verify sufficient margin
- Review session filter settings
- Check "PAUSE ADDS" not active
- Verify position limits not reached
- Review price step settings
- Check exit mode configuration
- Verify profit target is realistic
- Review time settings
See USER_GUIDE.md troubleshooting section for complete solutions.
- ✅ Core pyramid strategy
- ✅ Two-sided pending orders
- ✅ Arithmetic/Geometric lots
- ✅ Multiple exit modes
- ✅ Virtual TP/SL
- ✅ Trailing stop
- ✅ Trading sessions
- ✅ DDR logic
- ✅ Interactive panel
- ✅ Comprehensive logging
Before Contacting Support:
- Read USER_GUIDE.md thoroughly
- Check TEST_INSTRUCTIONS.md
- Review Experts log for errors
- Test with default settings
- Verify MT4 is updated
This software is provided "as-is" for educational and testing purposes. The developer assumes no responsibility for trading losses or any damages arising from the use of this EA.
✅ Correct two-sided re-placing: Verified ✅ ≈6-pip add spacing: Implemented ($0.62/$0.68 USD steps) ✅ Proper Arithmetic/Geometric lots: Both modes supported ✅ Basket settlement: All legs close within seconds ✅ Cancel-and-replace behavior: Fully functional ✅ Comprehensive logging: Time, action, broker codes included
- Copy files to MT4 directories
- Compile EA (0 errors)
- Load default .set file
- Attach to XAUUSD M1
- Enable live trading
- Verify panel displays
- Run backtest
- Forward test on demo
- Monitor 1-2 days
- Optimize if needed
- Go live cautiously
Made with precision for professional traders
Happy Trading! 📈